IllegalAnnotationsException SetMultimap是一个接口,JAXB无法处理接口 [英] IllegalAnnotationsException SetMultimap is an interface, and JAXB can't handle interfaces

查看:86
本文介绍了IllegalAnnotationsException SetMultimap是一个接口,JAXB无法处理接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

private SetMultimap<String, Dynamic> dynamicFields = TreeMultimap.create(Ordering.natural(), new Comparator<Dynamic>() {
  @Override
  public int compare(Dynamic o1, Dynamic o2) {
   return o1.getTitle().compareTo(o2.getTitle());
  }
 });

这给我以下例外。

IllegalAnnotationsException SetMultimap is an interface, and JAXB can't handle interfaces

我的问题是,为什么这不起作用但是这样做:

My question is, how come this doesn't work but this does:

List<Dynamic> test = new ArrayList<Dynamic>();

我如何修复SetMultimap以便JAXB满意?

And how can I fix the SetMultimap so that JAXB is happy?

推荐答案

List / ArrayList和SetMultimap之间的区别在于,一个是Java集合,另一个是普通Java集合层次结构之外的数据结构。这意味着JAXB认为它是普通类。

The difference between List/ArrayList and SetMultimap is that one is a Java collection, and the other is a data structure outside the normal Java collection hierarchy. This means JAXB considers it a normal class.

JAXB规范不支持接口。您可能正在使用Metro JAXB实现,该实现也不支持接口。某些JAXB实现(如 MOXy )可以支持接口,但某些JAX-WS实现依赖于一个特定的JAXB impl,并不总是可以替换JAXB实现:

The JAXB spec does not support interfaces. You are probably using the Metro JAXB implementation which also does not support interfaces. Some JAXB implementations such as MOXy can support interfaces, but some JAX-WS implementations depend upon a particular JAXB impl, and substituting JAXB implementations is not always possible:

  • http://bdoughan.blogspot.com/2010/07/moxy-jaxb-map-interfaces-to-xml.html
  • http://bdoughan.blogspot.com/2010/07/jaxb-xml-binding-standard.html

最好的办法是使用参数级别注释将SetMultimap转换为可由JAXB处理的类:

Your best bet is to use a parameter level annotation to convert SetMultimap to a class that can be handled by JAXB:


  • < a href =http://bdoughan.blogspot.com/2010/07/xmladapter-jaxbs-secret-weapon.html =nofollow noreferrer> http://bdoughan.blogspot.com/201 0/07 / xmladapter-jaxbs-secret-weapon.html

  • http://bdoughan.blogspot.com/2010/07/xmladapter-jaxbs-secret-weapon.html

这篇关于IllegalAnnotationsException SetMultimap是一个接口,JAXB无法处理接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆