2

During a recent job interview, i was asked the steps taken to convert Java object to JSON using Jackson. Although, I havent done it before, I have seen examples where Jackson was used and by using object mapper the java object is converted to JSON. However, the interviewer asked "how and where is the JSON schema set up" I thought this was done automatically. Does one have to specify how the JSON has to be returned? I have seen examples where the toString is overriden - is that where the schema is specified. Thanks

1 Answer 1

2

I think the interviewer doesn't mean to ask you how to use Jackson, but how JSON is constructed from a Java Object.

Here's what I thought:

  1. Jackson will detect every field's name as keys;
  2. Iterate the keys to get their values and put it into the JSON.
  3. If a field has child object, it will do step 1 and 2 recursively.

Note: The Java class should implementation the serialization interface.

Sign up to request clarification or add additional context in comments.

2 Comments

Not necessarily. Jackson can serialize classes that aren't marked as Serializable.
As said, theres others ways of doing the serialization. And, the way you said is so simple to the real implementation, that needs to detect the type of the object, how it should be codec/decoded, etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.