title: How to Store Json Object as a string in a Single Column in java
body: <p>How to save/retrieve below Json Object into database like all rule should contain array as string:</p>
  
  <pre><code>[{"ID":1,
   "parentId":1,
   "level":1,
    "rule":"abc",
   "fieldName":"cds",
   "allrule":[
    {}
     ]
     },
    {"ID":2,
    "parentId":2,
    "level":2,
    "rule":"abcas",
    "fieldName":"cdgf",
    "allrule":[{"firstname":"rohit","min":5,"max":10}
    ]
    }
    ]
  </code></pre>
  
  <p>Here values inside "all rule" object can be dynamic like there could be any no of key value pair at run time.
  I hope its not confusing problem statement
  I tried @OneToMany logic and stored Json object data in separate table Code snippet:  </p>
  
  <pre><code>@Entity
  @Table(name = "Allrule")
  public class ListofRules {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int allruleId;
      private String key1;
      private String value1;
      @ManyToOne(cascade = { CascadeType.ALL })
      private Rule rule;
  //getters,setters
  
  @Entity
  @Table(name = "Rule")
  public class Rule {
  
      @Id
      private int ID;
      private int parentId;
      private int level;
      private String rule;
      private String fieldName;
  
      @OneToMany(fetch = FetchType.EAGER,cascade= {CascadeType.ALL})
      @JoinColumn(name="rule_id")
      private List&lt;ListofRules&gt; listofrules;
  
      //getter,setter
   }
  </code></pre>
  
  <p>But I need to save and retrive Json data as below Output like below:
   As per my logic I am getting json response like:</p>
  
  <pre><code>[
   {"ID":1,
   "parentId":1,
   "level":1,
   "rule":"abc",
  "fieldName":"cds",
   allrule":[{}]
   },
   {"ID":2,
   "parentId":2,
   "level":2,
   "rule":"abcas",
   "fieldName":"cdgf",
   "allrule":[{"Key1":"rohit","value1":5},{"Key1":"dinesh","value1":19}]
   }
   ]
  </code></pre>