title: Specification Predicate to Search Nested jsonb column Objects
body: <p>I have stored jsonb object in postgresql like</p>
  
  <pre><code>{"sample": {"lastName": "Sahani", "firstName": "Sanjay"}, "address": "Address2", "bedrooms": 2, "postcode": "40 BS", "propertyType": "Type 2"}
  </code></pre>
  
  <p>My table name is <strong>valuation_report_json</strong>
  and <strong>jsonb column</strong> name is <strong>params</strong>
  I can get address using Specification but unable to get sample's firstName
  My specification is </p>
  
  <pre><code>public class ValuationReportJSONSpecification implements Specification&lt;ValuationReportJSON&gt;{
  
      private String locale;
      private String fieldToSearch;
      private String localeParameter;
  public ValuationReportJSONSpecification(String locale, String fieldToSearch,String localeParameter) {
          this.locale = locale;
          this.fieldToSearch = fieldToSearch;
          this.localeParameter=localeParameter;
      }
  @Override
      public Predicate toPredicate(Root&lt;ValuationReportJSON&gt; root, CriteriaQuery&lt;?&gt; query, CriteriaBuilder cb) {
          // TODO Auto-generated method stub
          System.err.println("INSIDE");
  //      return cb.equal(cb.function("jsonb_extract_path_text", String.class, root.&lt;String&gt;get("params"), cb.literal(this.locale)), this.fieldToSearch);
          return cb.equal(cb.function("jsonb_extract_path_text", String.class,root.&lt;String&gt;get("params"), cb.literal(this.locale),cb.literal(this.localeParameter)),this.fieldToSearch);
      }
  }
  </code></pre>
  
  <p>My models are
  <strong>ValuationReportJSON</strong> :</p>
  
  <pre><code>@Data
  @NoArgsConstructor
  @Entity
  @JsonIgnoreProperties(ignoreUnknown = true)
  @Table(name = "valuation_report_json")
  @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
  public class ValuationReportJSON implements Serializable{
  
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      @Type(type = "jsonb")
      @Column(name = "parameters", nullable = false,columnDefinition = "jsonb")
      private Params params;
  
      @OneToOne(cascade = CascadeType.PERSIST)
      @JoinColumn(name = "property_id", nullable = true)
      private Property property;
  
      @Column(name = "entry_id", nullable = true)
      private Integer entryId;
  
      @Column(name = "report_data", nullable = true, columnDefinition = "text")
      private String reportData;
  
      @Column(name = "entry_date", nullable = true)
      @CreationTimestamp
      private Timestamp entryDate;
  
      @Column(name = "modified_date", nullable = true)
      @UpdateTimestamp
      private Timestamp modifiedDate;
  //getter setter
  }
  </code></pre>
  
  <p><strong>Params</strong></p>
  
  <pre><code>@Data
  @NoArgsConstructor
  @AllArgsConstructor
  public class Params implements Serializable{
  
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
  
      public String address;
  
      private String postcode;
  
      private SampleObj sample;
  
      private int bedrooms;
  //getter setter
  }
  </code></pre>
  
  <p><strong>SampleObj</strong>:</p>
  
  <pre><code>@Data
  @NoArgsConstructor
  @AllArgsConstructor
  public class SampleObj implements Serializable{
  
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
  
      private String firstName;
  
      private String lastName;
  //getter setter
  }
  </code></pre>
  
  <p>I cannot use join in predicate as my objects are not having mapping or not an entity.
  because i have seen same question but objects were entity :<a href="https://stackoverflow.com/questions/42465419/specification-predicate-to-search-nested-objects">Specification/Predicate to Search Nested Objects</a></p>