My target is xml to Pojo and Pojo to json. I already did xml to pojo using jaxb. Now I am trying pojo to json using jackson Jaxb. Where I am getting the following json which produce JXBElement class fileds in json like following.
{
"name" : "{http://xxx.xx.xx.xx.xx.xx.xx}CompositeResponse",
"declaredType" : "xxx.xx.xx.xx.xx.xx.xxCompositeResponseType",
"scope" : "javax.xml.bind.JAXBElement$GlobalScope",
"value" : {
"CompositeIndividualResponse" : [ {
"ResponseMetadata" : {
"ResponseCode" : "HS000000",
"ResponseDescriptionText" : "Success"
}
} ]
},
"nil" : false,
"globalScope" : true,
"typeSubstituted" : false
}
How Can I removed name, declaredType,scope,nil, globalScope,typeSubstituted ang get the following json
{
"CompositeResponse":
{
"CompositeIndividualResponse" : [ {
"ResponseMetadata" : {
"ResponseCode" : "HS000000",
"ResponseDescriptionText" : "Success"
}
} ]
}
}
I was looking this post but this does not work for me.
The following code I have tried for jackson mixin.
public class Main {
public static interface JAXBElementMixinT {
@JsonValue
Object getValue();
}
public static void main(String[] args) throws XMLStreamException, IOException {
ObjectMapper mapper = new ObjectMapper();
AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(mapper.getTypeFactory());
mapper.setAnnotationIntrospector(introspector );
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.addMixIn(JAXBElement.class, JAXBElementMixinT.class);
String result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(employee);
System.out.println(result);
}
}
I also tried with following code but no luck.
public abstract class JAXBElementMixIn {
@JsonIgnore abstract String getScope();
@JsonIgnore abstract boolean isNil();
@JsonIgnore abstract boolean isGlobalScope();
@JsonIgnore abstract boolean isTypeSubstituted();
@JsonIgnore abstract Class getDeclaredType();
}
Can anyone help me where I am wrong and what to do thanks.