1

I want to response using json in web service like this :

HTTP/1.1 200 OK
Content-Type: application/vnd.org.snia.cdmi.dataobject+json
X-CDMI-Specification-Version: 1.0
{
"objectURI" : "/MyContainer/MyDataObject.txt",
"objectID" : "AABwbQAQb/ENV52Ai8a3MA==",
"parentURI" : "/MyContainer/",
"mimetype" : "text/plain",
"metadata" : {
"cdmi_size" : "17"
},
"valuerange" : "0-17",
"value" : "Hello CDMI World!"
}

But now I can only show like

HTTP/1.1 200 OK
Content-Type: application/vnd.org.snia.cdmi.dataobject+json
X-CDMI-Specification-Version: 1.0
{
"objectURI" : "/MyContainer/MyDataObject.txt",
"objectID" : "AABwbQAQb/ENV52Ai8a3MA==",
"parentURI" : "/MyContainer/",
}   

How to put "meta" : {....} after "mimetype" from above .And how to get the "meta" as BasicDBObject or other types?I write web service using jersey framework and java.

thanks

1 Answer 1

1

You will need to use JAXB Binding annotations to annotate your objects before Jersey serializes them to JSON. Below is an example class, note that you can reorder elements with the propOrder attribute of the @XmlType annotation. It is also possible to give XML elements names other than their method names.

@XmlRootElement
@XmlType(propOrder = { "name", "elements" })
public class ExampleObject implements Serializable {

    private static final long serialVersionUID = 1L;
    private Collection<String> elements = null;
    private String name = null;

    @XmlElementWrapper(name = "elements")
    @XmlElement(name = "element")
    public Collection<String> getElements() {
        return this.elements;
    }

    public String getName() {
        return this.name;
    }

    public void setElements(final Collection<String> elements) {
            this.elements = elements;
    }

    public void setName(final String name) {
            this.name = name;
    }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.