Note that there are some explanatory texts on larger screens.

plurals
  1. POOrder of JSON objects using Jackson's ObjectMapper
    text
    copied!<p>I'm using <em>ObjectMapper</em> to do my java-json mapping.</p> <pre><code>ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); ow.writeValue(new File( fileName +".json"), jsonObj); </code></pre> <p>this is my java class:</p> <pre><code>public class Relation { private String id; private String source; private String target; private String label; private List&lt;RelAttribute&gt; attributes; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getSource() { return source; } public void setSource(String source) { this.source = source; } public String getTarget() { return target; } public void setTarget(String target) { this.target = target; } public String getLabel() { return label; } public void setLabel(String label) { this.label = label; } public void setAttributes(List&lt;RelAttribute&gt; attributes) { this.attributes = attributes; } public List&lt;RelAttribute&gt; getAttributes() { return attributes; } } </code></pre> <p>this is what I get:</p> <pre><code>{ "id" : "-75da69d3-79c8-4000-a3d8-b10350a57a7e", "attributes" : [ { "attrName" : "ID", "attrValue" : "" }, { "attrName" : "Description", "attrValue" : "Primary Actor" }, { "attrName" : "Status", "attrValue" : "" } ], "label" : "new Label", "target" : "-46b238ac-b8b3-4230-b32c-be9707f8b691", "source" : "-daa34638-061a-45e0-9f2e-35afd6c271e0" } </code></pre> <p>So my question now is, how can I get this json output:</p> <pre><code>{ "id" : "-75da69d3-79c8-4000-a3d8-b10350a57a7e", "label" : "new Label", "target" : "-46b238ac-b8b3-4230-b32c-be9707f8b691", "source" : "-daa34638-061a-45e0-9f2e-35afd6c271e0", "attributes" : [ { "attrName" : "ID", "attrValue" : "" }, { "attrName" : "Description", "attrValue" : "Primary Actor" }, { "attrName" : "Status", "attrValue" : "" } ] } </code></pre> <p>I want it with same order as in my java declaration. Is there a way to specify it ? Maybe with annotations or stuff like that ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload