Serialization third-party classes with Simple XML (org.simpleframework.xml)

后端 未结 3 1590
鱼传尺愫
鱼传尺愫 2021-02-04 04:32

I have decided to use Simple XML serialization and was stucked with basic problem. I am trying to serialize java.util.UUID class instance as final field in this sma

相关标签:
3条回答
  • 2021-02-04 05:10

    I know this is a bit aold but my chance i came to the same exception.

    The actual issue is the use of the @Attribute annotation. If instead of @Attribute you put @Element the exception does not appear and the converter is used for the serialization.

    I guess it will then depend on which annotation you used that you should create a Converter or use the Marker-Transform solution. Although i do not know if this is the intendent behaviour.

    0 讨论(0)
  • 2021-02-04 05:19

    I have to answer by myself again :-)

    Advice from Niall Gallagher, project leader of Simple XML, from support-list:

    "You could use either a Converter or a Transform. I would say for a UUID a Transform with a Matcher would be the easiest option."

    So, I use Transform<T>/Matcher and satisfied with it. This does not alter the fact that the Converter<T> does not work for me :-)

    0 讨论(0)
  • 2021-02-04 05:20

    I think i have the answer to this.

    Strategy strategy = new AnnotationStrategy();
    Serializer serializer = new Persister(strategy);
    

    should register the converter and solve the problem.

    0 讨论(0)
提交回复
热议问题