How to serialize java object as xml attribute with jackson?

后端 未结 2 1872
说谎
说谎 2021-01-17 23:33

is there a way to serialize a java var (e.g. int) via jackson as an xml attribute? I can not find any spezific jackson or json annotation (@XmlAttribute @javax.xml.bind.anno

2条回答
  •  情书的邮戳
    2021-01-17 23:48

    Have you registered JaxbAnnotationIntrospector?

    ObjectMapper mapper = new ObjectMapper();
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    // make deserializer use JAXB annotations (only)
    mapper.getDeserializationConfig().setAnnotationIntrospector(introspector);
    // make serializer use JAXB annotations (only)
    mapper.getSerializationConfig().setAnnotationIntrospector(introspector);
    

提交回复
热议问题