title: org.codehaus.jackson.JsonGenerationException: Can not write number, expecting field name
body: <p>Hi i am working on a spring mvc application well i need to Serialize an object in order to pass it with an ajax Post.</p>
  
  <p>my bean class : </p>
  
  <pre><code>@JsonSerialize(using = AgentSer.class)
  public class AgentCust implements Serializable {
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
      private Long personneID;
      private String nom;
      private String prenom;
      private String matriculation;
      private String marche;
      private String compte;
      private String phone, mail, chat;
  
      public String getMarche() {
          return marche;
      }
  
      public void setMarche(String marche) {
          this.marche = marche;
      }
  
      public String getCompte() {
          return compte;
      }
  
      public void setCompte(String compte) {
          this.compte = compte;
      }
  
      public String getPhone() {
          return phone;
      }
  
      public void setPhone(String phone) {
          this.phone = phone;
      }
  
      public String getMail() {
          return mail;
      }
  
      public void setMail(String mail) {
          this.mail = mail;
      }
  
      public String getChat() {
          return chat;
      }
  
      public void setChat(String chat) {
          this.chat = chat;
      }
  
      public Long getPersonneID() {
          return personneID;
      }
  
      public void setPersonneID(Long personneID) {
          this.personneID = personneID;
      }
  
      public String getNom() {
          return nom;
      }
  
      public void setNom(String nom) {
          this.nom = nom;
      }
  
      public String getPrenom() {
          return prenom;
      }
  
      public void setPrenom(String prenom) {
          this.prenom = prenom;
      }
  
      public String getMatriculation() {
          return matriculation;
      }
  
      public void setMatriculation(String matriculation) {
          this.matriculation = matriculation;
      }
  }
  </code></pre>
  
  <p>and the class that will serialize my bean : </p>
  
  <pre><code>public class AgentSer extends JsonSerializer&lt;AgentCust&gt; {
      @Override
      public void serialize(AgentCust value, JsonGenerator jgen, SerializerProvider arg2) throws IOException, JsonProcessingException {
          // TODO Auto-generated method stub
          jgen.writeStartObject();
          jgen.writeNumber(value.getPersonneID());
          jgen.writeString(value.getMatriculation());
          jgen.writeString(value.getNom());
          jgen.writeString(value.getPrenom());
          jgen.writeString(value.getCompte());
          jgen.writeString(value.getMarche());
          jgen.writeString(value.getChat());
          jgen.writeString(value.getMail());
          jgen.writeString(value.getPhone());
          jgen.writeEndObject();
      }
  }
  </code></pre>
  
  <p>in my controller i use my class like that:</p>
  
  <pre><code>                AgentCust ags ;
                  // i set values here .
                  ObjectMapper mapper = new ObjectMapper();
                  String json = "";
                  try { 
  
                      json = mapper.writeValueAsString(ags);
                  } catch (Exception e) {
                      System.out.println(e);
                  }
  </code></pre>
  
  <p>but at the end i get that : </p>
  
  <p>org.codehaus.jackson.JsonGenerationException: Can not write number, expecting field name</p>
  
  <p>any help please.</p>