title: How display in json only one attribute of an entity in a oneToMany with itself?
body: <p>I have a class embedded herself with a oneToMany relationship: </p>
  
  <pre><code>@Entity
  public class A {
  
    private String id;
  
    @OneToMany(fetch = FetchType.EAGER)
    private List&lt;A&gt; parents;
  }
  </code></pre>
  
  <p>Thanks to the fetch, I can display easily the complete json of each parents. </p>
  
  <p>But to avoid over data and loop, I would display only id of the item from "parents". </p>
  
  <p>Any clues ? 
  Thank you. </p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>After answer of marians27, I think about the reverse problem, for PUT and POST. 
  But how to do it for PUT/POST ? </p>
  
  <p>By example, knowing that the object "embeded_id" is already in my database, I wanna pass to my API a json like : </p>
  
  <pre><code>{"A":
     {
     "id":"new_object_id",
     "parents":
       [{
       "id":"embeded_id"
       }]
     }
  }
  </code></pre>
  
  <p>instead of : </p>
  
  <pre><code>{"object":
     {
     "id":"new_object_id",
     "parents":
       [{
       "id":"embeded_id",
       "parents":[{...}]
       }]
     }
  }
  </code></pre>
  
  <p>Here is the solution I found from <a href="http://www.davismol.net/2015/05/20/jackson-create-a-custom-json-deserializer-with-stddeserializer-and-jsontoken-classes/" rel="nofollow">here</a>:</p>
  
  <pre><code>@Service
  public class DeserializeA extends StdDeserializer&lt;A&gt; {
  
    @Autowired
    private IManager manager;
  
    public DeserializeA() {
      super(A.class);
    }
  
    public DeserializeA(Class&lt;A&gt; t) {
      super(t);
    }
  
    @Override
    public A deserialize(JsonParser jp, DeserializationContext arg1)
        throws IOException, JsonProcessingException {
      String id = null;
      JsonToken currentToken = null;
      while ((currentToken = jp.nextValue()) != null) {
        switch (currentToken) {
          case VALUE_STRING:
            switch (jp.getCurrentName()) {
              case "id":
                id = jp.getText();
                break;
              default:
                break;
            }
            break;
          default:
            break;
        }
      }
  
      return manager.getAById(id);
    }
  }
  </code></pre>