java - How to convert POJO to JSON and vice versa? -


i want know if there java api available convert pojo object json object , vice versa.

yes, there json.org. take @ http://www.json.org/java/index.html

[edited] imagine have simple java class this:

public class person {      private string name;     private integer age;      public string getname() { return this.name; }     public void setname( string name ) { this.name = name; }      public integer getage() { return this.age; }     public void setage( integer age ) { this.age = age; }  } 

so, transform json object, it's simple. this:

import org.json.jsonobject;  public class jsontest {      public static void main( string[] args ) {         person person = new person();         person.setname( "person name" );         person.setage( 666 );          jsonobject jsonobj = new jsonobject( person );         system.out.println( jsonobj );     }  } 

hope helps.

[edited] here there other example, in case using jackson: https://brunozambiazi.wordpress.com/2015/08/15/working-with-json-in-java/


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -