title: How to make Jackson not to write to @GeneratedValue fields?
body: <p>I'm using JPA, Jackson and JAX-RS in the following way.</p>
  
  <p>My entity:</p>
  
  <pre><code>import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  
  @Entity
  public class Person {
  
      @Id
      @GeneratedValue
      private long id;
  
      private String name;
      private int age;
  
      public long getId() {
          return id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public int getAge() {
          return age;
      }
  
      public void setAge(int age) {
          this.age = age;
      }
  
      public Person() {
      }
  
      public Person(String name, int age) {
          this.name = name;
          this.age = age;
      }
  
      @Override
      public String toString() {
          return "Person [id=" + id + ", name=" + name + ", age=" + age + "]";
      }
  }
  </code></pre>
  
  <p>This class has no setter for <code>id</code> because it's auto generated. Even if I put the setter there is no difference. I don't mind having it if Jackson needs it but it shouldn't be used anyway.</p>
  
  <p>This is the resource:</p>
  
  <pre><code>import java.io.IOException;
  
  import javax.inject.Inject;
  import javax.json.JsonObject;
  import javax.ws.rs.Consumes;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  
  import org.codehaus.jackson.map.ObjectMapper;
  
  import com.test.persons.entity.Person;
  
  @Path("persons")
  public class PersonResource {
  
      @Inject
      PersonService service;
  
      @POST
      @Consumes(MediaType.APPLICATION_JSON)
      @Produces(MediaType.APPLICATION_JSON)
      public Response save(JsonObject inputPerson) {
          ObjectMapper mapper = new ObjectMapper();
          Person person = null;
          try {
              person = mapper.readValue(inputPerson.toString(), Person.class);
          } catch (IOException e) {
              e.printStackTrace();
          }
          service.save(person); // calls @PersistenceContext EntityManager#persist(person)
          return Response.ok(person).build();
      }
  }
  </code></pre>
  
  <p>The problem is that the <code>inputPerson</code> comes with its own <code>id</code> which should be ignored and <code>person</code> should have auto generated its own <code>id</code>. But Jackson uses the <code>id</code> from <code>inputPerson</code> which results in an exception in the JPA layer (because the <code>@Id</code> is wrong).</p>
  
  <p>What I want is just to create a <code>Person</code> object with the properties of the given <code>Person</code> in <code>JsonObject</code> form and with its auto generated id. How can I achieve that?</p>
  
  <p>Note that I when I serialize a <code>Person</code> to Json <code>String</code> with</p>
  
  <pre><code>String s = mapper.writeValueAsString(person);
  </code></pre>
  
  <p>I do need the <code>id</code> to be serialized. Just not deserialized.</p>