Skip to content
Advertisement

Converting POJO into map

I have a Java class having 10 attributes, I want to convert this into 3 maps(Breaking it into 5,3,2 fields resepectively). I did some research and found that Jackson’s ObjectMapper can be used by doing something like this:

JavaScript

This will be creating a single map for all the attributes in my POJO.

What I want is have this POJO converted to 3 different maps(which essentialy are fields of a DynamoDB) I can either define 3 POJOs indivdually and use ObjectMapper on each of them separately, or is there some other way to do it where all fields remain in one POJO only?

I explored mapStruct(https://mapstruct.org/) couldn’t get much out of it. Thoughts?

Advertisement

Answer

You can create methods to get required maps.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement