Json version of XMLElements choice
Are you using spring?. I used a simple java class In simple java I got
{ "ContactUser" : { "Title" : "sampleTitle", "LastName" : "sampleLastName" }, "CompanyName" : "XXXXX"}
Could you rephrase your question. I think I quite not understand what is your intend.
This is my code:
@JsonProperty(value = "Contact")@XmlElements(value = { @XmlElement(name = "ContactUser", type = ContactUser.class, required = true) , @XmlElement(name = "CompanyName", type = String.class, required = true)})private Object contactInfo;public TestClassConstructor() throws JsonProcessingException { contactInfo = new HashMap<String, Object>(); ((HashMap) contactInfo).put("ContactUser", new ContactUser("sampleTitle", "sampleLastName")); ((HashMap) contactInfo).put("CompanyName", "XXXXX"); ObjectMapper mapper = new ObjectMapper(); String jsonResult = mapper.writerWithDefaultPrettyPrinter() .writeValueAsString(contactInfo); System.err.println(jsonResult);}
In case you wanted to have a specific serializer you need to check: http://www.baeldung.com/jackson-serialize-field-custom-criteria