hi
We have a Person class like this:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "person")
public class Person {
private String name;
private String sex;
private String age;
private int mark;
private Set<Child> childSet = new HashSet<Child>();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public Set<Child> getChildSet() {
return childSet;
}
public void setChildSet(Set<Child> childSet) {
this.childSet = childSet;
}
public int getMark() {
return mark;
}
public void setMark(int mark) {
this.mark = mark;
}
}
And Provider like this:
@Provider
public final class JAXBContextResolver implements
ContextResolver<JAXBContext> {
Map<String, Object> props = new HashMap<String, Object>();
private final JAXBContext context;
private final Class<?>[] classes = {Person.class};
public JAXBContextResolver() throws Exception {
Map<String, Object> props = new HashMap<String, Object>();
props.put(JSONJAXBContext.JSON_NOTATION,
JSONJAXBContext.JSONNotation.MAPPED);
props.put(JSONJAXBContext.JSON_ROOT_UNWRAPPING, Boolean.TRUE);
props.put(JSONJAXBContext.JSON_NON_STRINGS, new
HashSet<String>(1){{add("mark");}});
context = new JSONJAXBContext(classes, props);
}
public JAXBContext getContext(Class<?> objectType) {
return context;
}
}
Our Resource class is :
@Path("person")
public class PersonResource {
@GET
@Path("list")
@Produces("application/json")
public List<Person> getPersons() {
List<Person> list = new ArrayList<Person>();
for (int i=0; i<5; i++) {
Person p = new Person();
p.setName("redhacker" +1);
p.setAge("22");
p.setSex("1");
p.setMark(98);
list.add(p);
}
return list;
}
}
We have got a result is:
{"person":[{"name":"redhacker1","sex":"1","age":"22","mark":"98"},{"name":"redhacker1","sex":"1","age":"22","mark":"98"},{"name":"redhacker1","sex":"1","age":"22","mark":"98"},{"name":"redhacker1","sex":"1","age":"22","mark":"98"},{"name":"redhacker1","sex":"1","age":"22","mark":"98"}]}
But we hope to get the result like this:
[{"name":"redhacker1","sex":"1","age":"22","mark":"98"},{"name":"redhacker1","sex":"1","age":"22","mark":"98"},{"name":"redhacker1","sex":"1","age":"22","mark":"98"},{"name":"redhacker1","sex":"1","age":"22","mark":"98"},{"name":"redhacker1","sex":"1","age":"22","mark":"98"}]
NO have a prefix(person), can we realize this?
Any helps?
Thanks and Merry Christmas!
Jack.
--
View this message in context: http://n2.nabble.com/Can-i-take-out-the-json-document-prefix---tp1799407p1799407.html
Sent from the Jersey mailing list archive at Nabble.com.