Serialize using Jackson ObjectMapper

Madhur Ahuja

I am trying to serialize the below ArrayList of GAccount objects using Jackson library with following code:

List<Gaccount> gAccounts;
ObjectMapper mapper=new ObjectMapper();
json=mapper.writeValueAsString(gAccounts);

However, I have noticed that only Id and Name fields are serialized but not properties. Sorry, but I am new to Jackson library. Do I have to manually serialize that field ?

package in.co.madhur.ganalyticsdashclock;

import java.util.ArrayList;
import java.util.List;

public class GAccount
{
    private String Id;
    private String Name;
    private List<GProperty> properties=new ArrayList<GProperty>();

    public GAccount(String Id, String Name)
    {
        this.Id=Id;
        this.Name=Name;
    }

    public String getName()
    {
        return Name;
    }
    public void setName(String name)
    {
        Name = name;
    }
    public String getId()
    {
        return Id;
    }
    public void setId(String id)
    {
        Id = id;
    }

    List<GProperty> getProperties()
    {
        return properties;
    }

    void setProperties(List<GProperty> properties)
    {
        this.properties = properties;
    }

    @Override
    public String toString()
    {
        return Name;
    }

}
tom

The default visibility is to use all public getter methods and all public properties. If you make the getter this:

public List<GProperty> getProperties()

it should work.

You could also change the auto-detection defaults, but it's overkill here. See http://www.cowtowncoder.com/blog/archives/2011/02/entry_443.html for more info.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Serialize Set of UUID using Jackson

From Dev

Serialize vertx JsonObject using Jackson

From Java

Order of JSON objects using Jackson's ObjectMapper

From Dev

Jackson unable to Map Class using ObjectMapper

From Dev

Jackson ObjectMapper using custom Serializers and Deserializers

From Dev

Using Jackson ObjectMapper with Java 8 Optional values

From Dev

How to detect trailing garbage using Jackson ObjectMapper

From Dev

Convert a part of Json to HashMap using Jackson ObjectMapper

From Java

How to de/serialize an immutable object without default constructor using ObjectMapper?

From Dev

Using Jackson to (De)-serialize a Scala Case Class

From Dev

How to serialize boolean to JSON as strings using Jackson

From Dev

Using Jackson to serialize a Guava Optional<Integer> as a string

From Dev

How to serialize boolean to JSON as strings using Jackson

From Dev

Can I serialize a property using a Jackson @JsonView?

From Dev

How to deserialize interface fields using Jackson's objectMapper?

From Dev

JSON Deserialization Joda Money using Jackson ObjectMapper causes exception

From Dev

How to ignore pojo annotations while using Jackson ObjectMapper?

From Dev

Deserializing or serializing any type of object using Jackson ObjectMapper and handling exceptions

From Dev

Spring MVC: Deserialise query parameters to POJO using Jackson objectMapper

From Dev

Spring Boot ObjectMapper for @RequestBody annotation using Jackson Framework

From Java

Strange jackson ObjectMapper behavior

From Dev

Jackson ObjectMapper setSerializationInclusion() not working

From Dev

ObjectMapper error in Jackson

From Dev

Spark: broadcasting jackson ObjectMapper

From Dev

RESTEasy and ContextResolver<ObjectMapper> for Jackson

From Dev

Serialize Json into generic structure without schema using Java and Jackson

From Dev

How to serialize output from custom method to JSON using Jackson?

From Dev

How to serialize complex Json object to QueryString for HTTP Get using Jackson?

From Dev

How to (de)serialize an EnumMap using Jackson and default typing?

Related Related

  1. 1

    Serialize Set of UUID using Jackson

  2. 2

    Serialize vertx JsonObject using Jackson

  3. 3

    Order of JSON objects using Jackson's ObjectMapper

  4. 4

    Jackson unable to Map Class using ObjectMapper

  5. 5

    Jackson ObjectMapper using custom Serializers and Deserializers

  6. 6

    Using Jackson ObjectMapper with Java 8 Optional values

  7. 7

    How to detect trailing garbage using Jackson ObjectMapper

  8. 8

    Convert a part of Json to HashMap using Jackson ObjectMapper

  9. 9

    How to de/serialize an immutable object without default constructor using ObjectMapper?

  10. 10

    Using Jackson to (De)-serialize a Scala Case Class

  11. 11

    How to serialize boolean to JSON as strings using Jackson

  12. 12

    Using Jackson to serialize a Guava Optional<Integer> as a string

  13. 13

    How to serialize boolean to JSON as strings using Jackson

  14. 14

    Can I serialize a property using a Jackson @JsonView?

  15. 15

    How to deserialize interface fields using Jackson's objectMapper?

  16. 16

    JSON Deserialization Joda Money using Jackson ObjectMapper causes exception

  17. 17

    How to ignore pojo annotations while using Jackson ObjectMapper?

  18. 18

    Deserializing or serializing any type of object using Jackson ObjectMapper and handling exceptions

  19. 19

    Spring MVC: Deserialise query parameters to POJO using Jackson objectMapper

  20. 20

    Spring Boot ObjectMapper for @RequestBody annotation using Jackson Framework

  21. 21

    Strange jackson ObjectMapper behavior

  22. 22

    Jackson ObjectMapper setSerializationInclusion() not working

  23. 23

    ObjectMapper error in Jackson

  24. 24

    Spark: broadcasting jackson ObjectMapper

  25. 25

    RESTEasy and ContextResolver<ObjectMapper> for Jackson

  26. 26

    Serialize Json into generic structure without schema using Java and Jackson

  27. 27

    How to serialize output from custom method to JSON using Jackson?

  28. 28

    How to serialize complex Json object to QueryString for HTTP Get using Jackson?

  29. 29

    How to (de)serialize an EnumMap using Jackson and default typing?

HotTag

Archive