'How to receive a JSON File with multiple nodes through a POST Request with JAX-RS and Jackson (Quarkus)

When im tryin got do a Post request through my JAX-RS API it always sends a null value. I dont know if the Jackson annotations are incorrect or if i need to use an ObjectMapper.

These are my classes:

public class ClassA{

  private String name;
  private ClassB classB;

public ClassA(){}

public ClassA(String name, ClassB classB){
   this.name = name;
   this.classB = classB;
}

@JsonGetter
public String getName(){ return name; }
@JsonGetter
public ClassB getClassB(){ return classB; }

and this is the classB

public class ClassB{

@JsonProperty("type")
private String type;
@JsonProperty("number")
private int number;

public ClassB(){}

@JsonPropertyOrder({"type, number"})
public ClassB(String type, int number){
   this.type= type;
   this.number= number;
}

@JsonGetter
public String getType(){ return type; }
@JsonGetter
public int getNumber(){ return number; }

My JSON file:

{
  "type": "typeExample;
  "classB": {
    "type": "classBTypeExample";
    "int": 10;
  }
}

I want Jackson to read the file and then add an Object type ClassA to a list (the problem is that is not even reading it) This is the API code:

@Path("/path")
public class Requests {
    private Set<ClassA> classesA = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>()));

    @GET
    public Set<ClassA> list() {
            return classesA;
        }

    @POST
    public Set<ClassA> add(ClassA classA){
        classesA.add(classA);
        return classesA;
    }
}

I already added the quarkus.jackson.fail-on-unknown-properties=true to the application.properies file



Solution 1:[1]

It was a simple thing that i didnt notice. I forgot to set the values on the constructer. So i just had to add the @ConstructorProperties({}) to the classes constructors and it worked out.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Diogo Teixeira