Jackson Object Mapper

Introducing, the black magic that is the objectMapper. This library is the go to, state of the art, hands down #1 place to go for translating Json to a java class and vis-versa.

Here is the link to the library if you want to dive deep in all the things you can do with ObjectMapper.

In this short tutorial, we will show how powerful the ObjectMapper is by serializing to and from a Classroom java object — which itself will contain a List of Person Objects — so there will be a decent level of complication since our Classroom is composed of Persons.

Storing Objects as Json

The Java Classes:

Say we have a classroom object

public class ClassRoom {
	    private String className;
	    private List<Person> members;

	    public ClassRoom() {
	    }

	    public ClassRoom(String className, List<Person> members) {
	        this.className = className;
	        this.members = members;
	    }

	    public String getClassName() {
	        return className;
	    }

	    public void setClassName(String className) {
	        this.className = className;
	    }

	    public List<Person> getMembers() {
	        return members;
	    }

	    public void setMembers(List<Person> members) {
	        this.members = members;
	    }
	}

In this ClassRoom object📚👨🏻‍🏫📎, we have a String for the name of the class, and a list of members in the class. The members are of the object type Person🙋🏻‍♂️.

#java #objectmapper #json #jackson #storage

Easily Translate Complex Java Objects To And From Json Like APro
5.50 GEEK