I have created the REST response as below
@XmlRootElement(name = "customer_info")
@JsonIgnoreProperties(value = { "map" })
public class Customer {
private String name;
private Integer id;
private long time;
private Map<String, Object> map = new TreeMap<>();
@JsonAnyGetter
public Map<String, Object> getMap() {
return map;
}
@JsonAnySetter
public void setMap(String name, Object values) {
this.map.put(name, values);
}
}
I want to dynamically create this response with addional parameter.The backend returns a map which will contains addional prop for this.
<customer_info>
<name></name>
<id></id>
<!--The below will have dynamic prop based on key-->
<dynamic1></dynamic1>
<dynamic2></dynamic2>
</customer_info>
The application config
ResourceConfig config = new DefaultResourceConfig();
config.add(resources);
Map<String, MediaType> type = config.getMediaTypeMappings()
type.put("json", MediaType.APPLICATION_JSON_TYPE);
type.put("xml", MediaType.APPLICATION_XML_TYPE);
servletHandler.addServlet(new ServletHolder(new ServletContainer(config)), "/*");
When i add the Map the xml structure appears as below which is not correct.I need the above xml structure.Can someone guide me how to implement this?
Also the name of the XML element should be same as the key in the map.The JSON response works fine but xml structure is not correct.
<customer_info>
<name></name>
<id></id>
<!--The below will have dynamic prop based on key-->
<map>
<entry>
<key>dummy_param1</key>
<value>11</value>
</entry>
<entry>
<key>dummy_param2</key>
<value>10</value>
</entry>
<map>
</customer_info>
I am using Jersey as REST framework and its running in Jetty server. I am using the provider and getting it registered using springs along with the REST service.
<bean class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider"/>
<bean class="com.dummy.CustomerService"/>
<bean class="com.dummy.Service2"/>
<bean class="com.dummy.Service3"/>
The library gradle config is as below:
"org.codehaus.jackson:jackson-core-asl:1.9.2",
"org.codehaus.jackson:jackson-jaxrs:1.9.2",
"org.codehaus.jackson:jackson-mapper-asl:1.9.2",
"org.codehaus.jackson:jackson-xc:1.9.2",
"com.sun.jersey:jersey-client:1.12",
"com.sun.jersey:jersey-core:1.12",
"com.sun.jersey:jersey-json:1.12",
"com.sun.jersey:jersey-server:1.12",
"com.sun.jersey:jersey-servlet:1.12",
"org.codehaus.jettison:jettison:1.1",
"javax.ws.rs:jsr311-api:1.1.1",
"com.sun.jersey.contribs:jersey-apache-client:1.12",
"com.sun.jersey.contribs:jersey-apache-client4:1.12",
"com.sun.jersey.contribs:jersey-multipart:1.12",
"com.sun.jersey:jersey-client:1.12",
"com.sun.jersey:jersey-core:1.12",
"com.sun.jersey:jersey-json:1.12",
"javax.ws.rs:jsr311-api:1.1.1",
"org.codehaus.jackson:jackson-core-asl:1.9.2",
"org.codehaus.jackson:jackson-jaxrs:1.9.2",
"org.codehaus.jackson:jackson-mapper-asl:1.9.2",
"org.codehaus.jackson:jackson-xc:1.9.2",
"javax.servlet:javax.servlet-api:3.1.0",
"org.eclipse.jetty:ecs-jetty-server:9.4.0.v20161208",
"org.eclipse.jetty:jetty-util:9.4.0.v20161208",
"org.eclipse.jetty:jetty-servlet:9.4.0.v20161208",
"org.eclipse.jetty:jetty-servlets:9.4.0.v20161208",
"org.eclipse.jetty:jetty-http:9.4.0.v20161208",
"org.eclipse.jetty:jetty-security:9.4.0.v20161208",
"org.eclipse.jetty:jetty-io:9.4.0.v20161208",
"org.eclipse.jetty:jetty-continuation:9.4.0.v20161208",
"org.eclipse.jetty:jetty-deploy:9.4.0.v20161208",
"org.eclipse.jetty:jetty-webapp:9.4.0.v20161208",
"org.eclipse.jetty:jetty-xml:9.4.0.v20161208"
Also can someone please suggest how above can be fixed? Thanks in advance.