7

I use jackson and sugar orm and i have some errors when parsing. The id field is located in the json constantly 0. What can I do to fix it?

This example my class:

@JsonIgnoreProperties(ignoreUnknown = true)
public class JsonScienceEvent extends SugarRecord<JsonScienceEvent>{

    @JsonProperty("id")
    private String eventId;

public JsonScienceEvent()

public JsonScienceEvent(String eventId){
    this.eventId = eventId;
}

public String getEventId(){
    return eventId;
}
Kota1921
  • 2,451
  • 1
  • 10
  • 13

2 Answers2

0

Sugar ORM actually creates its own ID field to maintain. If you're not inserting a value into the eventId field when creating a record, then your column is empty.

Try using "getId()" to get the auto incremented ID from the record. Don't forget to cast to a string if that's what you want back!

Tyler Kiser
  • 921
  • 8
  • 14
0

the fieldid is inherited from the super class SugarRecord<T> along with the setter and getter methods setId(Long id) and getId(). You can override the id field generated by the Sugar library, but as far as i can remember it uses Long type so if you can change from String identifier to Long all should be fine and, this way you can force the library to use the id you're setting with the setter setId(Long id),

3ammari
  • 144
  • 2
  • 10