小编Mar*_*fia的帖子

如何在 Unmarshal 中使用泛型(转到 1.18)

我是 golang 泛型的新手,并且有以下设置。

  1. 我收集了大量不同类型的报告。
  2. 每个报告都有封闭字段
  3. 所以我把它包裹在一个ReportContainerImpl

我使用了一个类型参数, [T Reportable]Reportable定义如下

type Reportable interface {
    ExportDataPointReport | ImportDataPointReport | MissingDataPointReport | SensorThresoldReport
}
Run Code Online (Sandbox Code Playgroud)

类型约束中的每个类型都是要嵌入到容器中的结构。

type ReportContainerImpl[T Reportable] struct {
    LocationID string `json:"lid"`
    Provider string `json:"pn"`
    ReportType ReportType `json:"m"`
    Body T `json:"body"`
}
Run Code Online (Sandbox Code Playgroud)

我使用鉴别器ReportType来确定何时的具体类型Unmarshal

type ReportType string

const (
    ReportTypeExportDataPointReport ReportType = "ExportDataPointReport"
    ReportTypeImportDataPointReport ReportType = "ImportDataPointReport"
    ReportTypeMissingDataPointReport ReportType = "MissingDataPointReport"
    ReportTypeSensorThresoldReport ReportType = "SensorThresoldReport"
)
Run Code Online (Sandbox Code Playgroud)

由于go不支持struct的类型断言(仅支持接口),因此无法在 when …

generics marshalling go unmarshalling

10
推荐指数
1
解决办法
8908
查看次数

为什么解析器线程不会在apache Felix中关闭

我正在尝试将Felix嵌入嵌入式Tomcat中.一切正常.但是,当关闭Felix框架(已部署SCR,cm,事件管理和元类型服务)时,它将为我提供框架关闭事件.但是线程在ResolveImpl执行器中仍然存在.

所以我有一堆"FelixResolver-"线程仍悬空.我不能强制关闭线程,因为它们属于执行程序.

关机顺序:

framework.stop();
final FrameworkEvent fe = framework.waitForStop(wait);
Run Code Online (Sandbox Code Playgroud)

我明白了

fe.getType() == FrameworkEvent.STOPPED.
Run Code Online (Sandbox Code Playgroud)

Felix Framework是'org.apache.felix.framework-5.6.1.jar'

我正在使用以下felix包:

  • org.apache.felix.configadmin-1.8.14.jar
  • org.apache.felix.eventadmin-1.4.8.jar
  • org.apache.felix.log-1.0.1.jar
  • org.apache.felix.metatype-1.1.2.jar
  • org.apache.felix.scr.compat-1.0.4.jar
  • org.apache.felix.scr-2.0.8.jar

我手动安装并启动捆绑包.我没有停止捆绑,而是使用上面的方法停止框架捆绑.

安装顺序(安装后的启动顺序相同​​):

  • org.apache.felix.configadmin [版本1.8.14]
  • org.apache.felix.eventadmin [版本1.4.8]
  • org.apache.felix.log [版本1.0.1]
  • org.apache.felix.metatype [版本1.1.2]
  • org.apache.felix.scr [版本2.0.8]
  • org.apache.felix.scr.compat [版本1.0.4]

我究竟做错了什么?

干杯,马里奥

编辑1:

我已升级到felix框架5.6.2,但问题仍然存在.

osgi resolver threadpool apache-felix

5
推荐指数
0
解决办法
201
查看次数

具有继承功能的反序列化Newtonsoft JSON.NET无法正常工作

(使用Newtonsoft JSON.NET)

嗨,我在反序列化事件列表时遇到了一个问题,其中Event是基本类型,例如ResourceEvent是子类。如果我只是进行序列化然后反序列化,一切正常,并且列表包含ResourceEvents-但是,我将使用EF7的事件存储在postgres的jsonb列中。

当我从postgres获取JSON有效负载时,它已经对属性进行了重新排序(但JSON合法)。当我尝试使用Newtonsoft JSON.net进行反序列化时,它只给我一个包含基本类型Event而不是子类ResourceEvent的列表。

我添加了两个高度剥离的示例,区别在于“ Type”属性在不同位置。在类中还对其他属性的顺序进行了排序。我根本没有在类上的注释。

此有效载荷成功地反硝化:

json
{
    "$type": "System.Collections.Generic.List`1[[Event, Tests]], mscorlib",
    "$values": [
        {
            "$type": "ResourceConfigurationEvent, Tests",
            /* Properties */
            "Resources": {
                /* Properties */                
            },
            "Type": 1            
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

该有效负载未能成功反序列化:

json
{
    "$type": "System.Collections.Generic.List`1[[Event, Tests]], mscorlib",
    "$values": [
        {
            "Type": 1,            
            "$type": "ResourceConfigurationEvent, Tests",
            /* Properties */
            "Resources": {
                /* Properties */                
            },
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

c# postgresql json json.net jsonb

3
推荐指数
1
解决办法
2034
查看次数

实体框架中的Postgresql表继承

我想知道是否可以在实体框架 7 中进行 postgres 表继承 - 而不是添加列,而是使用基表和继承基表的表来执行“真正的”postgres?

如果是这样,我该如何配置?

干杯,马里奥

postgresql npgsql entity-framework-core

3
推荐指数
1
解决办法
1780
查看次数