title: Spring Mongo Criteria Complex Query Matching inner object field of Querying entity
body: <p>I have two Entities </p>
  
  <pre><code>   class EntityA{
          @Id
          String id;
          ..... other class fields 
          ..... getter/setters
      }
  
     class EntityB{
     @Id
     String id;
     Integer age;
     EntityA entityA;
          ..... other class fields 
          ..... getter/setters
     }
  </code></pre>
  
  <p>and I am querying <strong>EntityB</strong> by matching the <code>id of entityA</code> objects. </p>
  
  <p>Here is what I'm trying to do</p>
  
  <pre><code>    Criteria criteria = Criteria.where("age").gte(0).lt(100);
  
      EntityA entityA = new EntityA();
      entityA.setId("theIdIHave");
      Example&lt;EntityA&gt; eaEx = Example.of(entityA);
      criteria = criteria.andOperator(Criteria.byExample(eaEx));
  
      Query query = new Query();
      query.addCriteria(criteria);
  
      List&lt;EntityB&gt; res = mongoTemplate.find(query,EntityB.class);
  </code></pre>
  
  <p>But it throws</p>
  
  <pre><code>java.lang.RuntimeException: json can't serialize type : class org.springframework.data.domain.Example
  </code></pre>
  
  <p>two things 
  Is my approach of using org.springframework.data.domain.Example is correct ??
  and why is error</p>