Using objectmapper for nested objects

So basically, I only needed to do was just use B class instead of Object

package servlet;

import lombok.Data;

@Data
public class A {
    public B key1;
}

and in servlet ask from A class both key1, key2 and loop them

@Override
    public void doPost(HttpServletRequest request,
                       HttpServletResponse response) throws IOException {

        String input = request.getReader().lines().collect(Collectors.joining("/n"));

        A a = new ObjectMapper().readValue(input, new TypeReference<A>() {});

        int sum = 0;
        for (Integer b: a.getKey1().getKey2()) {
            sum += b;
        }

        String output = new ObjectMapper().writeValueAsString(sum);
        response.getWriter().write(output);
    }