Java 杰克逊';s mixin类没有';别耍花招:虫子还是我做错了什么?
这是杰克逊2.3.3。我最近在杰克逊中学到了我正试图把它应用到课堂上。然而,到目前为止还没有成功。所讨论的类是一个静态类,可以转换为另一个类:Java 杰克逊';s mixin类没有';别耍花招:虫子还是我做错了什么?,java,jackson,deserialization,mixins,Java,Jackson,Deserialization,Mixins,这是杰克逊2.3.3。我最近在杰克逊中学到了我正试图把它应用到课堂上。然而,到目前为止还没有成功。所讨论的类是一个静态类,可以转换为另一个类: public static class Report { // Some non relevant public static final fields, then: public final int totalRuns; public final int totalInvocations; public final i
public static class Report
{
// Some non relevant public static final fields, then:
public final int totalRuns;
public final int totalInvocations;
public final int totalMatches;
public final int totalMismatches;
public final double matchShare;
public final int reinvocations;
public final int rematches;
public final int remismatches;
public final double reinvocationShare;
public final long totalNanoTime;
public final List<RuleReport> ruleReports;
public Report(final int totalRuns, final int totalMatches,
final int totalMismatches, final int rematches,
final int remismatches, final long totalNanoTime,
final List<RuleReport> ruleReports)
{
this.totalRuns = totalRuns;
this.totalInvocations = totalMatches + totalMismatches;
this.totalMatches = totalMatches;
this.totalMismatches = totalMismatches;
this.matchShare = (double) totalMatches / (double) totalInvocations;
this.reinvocations = rematches + remismatches;
this.rematches = rematches;
this.remismatches = remismatches;
this.reinvocationShare = (double) reinvocations
/ (double) totalInvocations;
this.totalNanoTime = totalNanoTime;
this.ruleReports = ruleReports;
}
// Other, non relevant methods
}
我真的不明白;我确实用@JsonCreator
注释了mixin类的构造函数,到目前为止,它一直对我“正常”反序列化有效(这是我第一次尝试mixin)
这是杰克逊的错误还是我做错了什么
编辑:
main
:
public static void main(final String... args)
throws IOException
{
final ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
mapper.registerModule(GrappaModule.INSTANCE);
final Closer closer = Closer.create();
final InputStream in;
try {
in = closer.register(ProfilingReportMixin.class.
getResourceAsStream("/profilingReports/test.json"));
if (in == null)
throw new IOException("resource not found");
final ProfilingParseRunner.Report report
= mapper.readValue(in, ProfilingParseRunner.Report.class);
mapper.writerWithDefaultPrettyPrinter()
.writeValue(System.out, report);
} finally {
closer.close();
}
}
以及模块
:
public final class GrappaModule
extends SimpleModule
{
private static final Version VERSION = new Version(1, 0, 0,
"beta.5-SNAPSHOT", "com.github.parboiled1", "grappa");
public static final Module INSTANCE = new GrappaModule();
private GrappaModule()
{
super("grappa", VERSION);
}
@Override
public void setupModule(final SetupContext context)
{
context.setMixInAnnotations(ProfilingParseRunner.RuleReport.class,
RuleReportMixin.class);
context.setMixInAnnotations(ProfilingParseRunner.Report.class,
ProfilingReportMixin.class);
}
}
确保mixin类上的ctor签名与目标类上的ctor签名匹配。您的目标类ctor将totalNanoTime作为long,但您的mixin ctor将totalNanoTime作为int
░░░░░░░░░▄░░░░░░░░░░░░░░▄░░░░
░░░░░░░░▌▒█░░░░░░░░░░░▄▀▒▌░░░
░░░░░░░░▌▒▒█░░░░░░░░▄▀▒▒▒▐░░░
░░░░░░░▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐░░░
░░░░░▄▄▀▒░▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐░░░
░░░▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌░░░
░░▐▒▒▒▄▄▒▒▒▒░░░▒▒▒▒▒▒▒▀▄▒▒▌░░
░░▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐░░
░▐░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄▌░
░▌░▒▄██▄▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▌░
▀▒▀▐▄█▄█▌▄░▀▒▒░░░░░░░░░░▒▒▒▐░
▐▒▒▐▀▐▀▒░▄▄▒▄▒▒▒▒▒▒░▒░▒░▒▒▒▒▌
▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒▒▒░▒░▒░▒▒▐░
░▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒░▒░▒░▒░▒▒▒▌░
░▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▒▄▒▒▐░░
░░▀▄▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▄▒▒▒▒▌░░
░░░░▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀░░░
░░░░░░▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀░░░░░
░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▀▀░░░░░░░░
这太不可思议了。确保mixin类上的ctor签名与目标类上的ctor签名匹配。您的目标类ctor将totalNanoTime作为long,但您的mixin ctor将totalNanoTime作为int
░░░░░░░░░▄░░░░░░░░░░░░░░▄░░░░
░░░░░░░░▌▒█░░░░░░░░░░░▄▀▒▌░░░
░░░░░░░░▌▒▒█░░░░░░░░▄▀▒▒▒▐░░░
░░░░░░░▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐░░░
░░░░░▄▄▀▒░▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐░░░
░░░▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌░░░
░░▐▒▒▒▄▄▒▒▒▒░░░▒▒▒▒▒▒▒▀▄▒▒▌░░
░░▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐░░
░▐░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄▌░
░▌░▒▄██▄▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▌░
▀▒▀▐▄█▄█▌▄░▀▒▒░░░░░░░░░░▒▒▒▐░
▐▒▒▐▀▐▀▒░▄▄▒▄▒▒▒▒▒▒░▒░▒░▒▒▒▒▌
▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒▒▒░▒░▒░▒▒▐░
░▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒░▒░▒░▒░▒▒▒▌░
░▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▒▄▒▒▐░░
░░▀▄▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▄▒▒▒▒▌░░
░░░░▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀░░░
░░░░░░▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀░░░░░
░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▀▀░░░░░░░░
太令人惊讶了。当你把
RuleReport
和Report
拉到他们自己的文件中时会发生什么事?@geo而且,我的目标并不是要把他们移走,确切地说……我明白了。然而,我现在不知道这样的事情有多有效。这就是我问的原因,所以我们有一种感觉,如果这是杰克逊不能处理的事情,或者看看你是否有错误的配置something@geoand错误配置:/5参数是长
,而不是int
。啊。这很简单:)当你把RuleReport
和Report
拉到它们自己的文件中时会发生什么呢?@geo而且,我们的目标并不是把它们移走,确切地说……我明白了。然而,我现在不知道这样的事情有多有效。这就是我问的原因,所以我们有一种感觉,如果这是杰克逊不能处理的事情,或者看看你是否有错误的配置something@geoand错误配置:/5参数是长
,而不是int
。啊。这很容易:)
░░░░░░░░░▄░░░░░░░░░░░░░░▄░░░░
░░░░░░░░▌▒█░░░░░░░░░░░▄▀▒▌░░░
░░░░░░░░▌▒▒█░░░░░░░░▄▀▒▒▒▐░░░
░░░░░░░▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐░░░
░░░░░▄▄▀▒░▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐░░░
░░░▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌░░░
░░▐▒▒▒▄▄▒▒▒▒░░░▒▒▒▒▒▒▒▀▄▒▒▌░░
░░▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐░░
░▐░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄▌░
░▌░▒▄██▄▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▌░
▀▒▀▐▄█▄█▌▄░▀▒▒░░░░░░░░░░▒▒▒▐░
▐▒▒▐▀▐▀▒░▄▄▒▄▒▒▒▒▒▒░▒░▒░▒▒▒▒▌
▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒▒▒░▒░▒░▒▒▐░
░▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒░▒░▒░▒░▒▒▒▌░
░▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▒▄▒▒▐░░
░░▀▄▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▄▒▒▒▒▌░░
░░░░▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀░░░
░░░░░░▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀░░░░░
░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▀▀░░░░░░░░