0

I am trying to save the following Java object as a document in MongoDB, here are my classes:

public class GenericIpConfig {
    String connection_type;
    String port;
    String port_ingenico;
    String ip;
    String ip_ingenico;
    String id_ingenico;
    boolean active_ingenico;
    long lastPushTime;
}

@Data
@Document(collection = "generic_device_config")
public class GenericDeviceConfig {
    @Id
    String _id;

    String storeCode;
    String companyCode;

    long updated;
    boolean enabled;

    ArrayList<SerialPort> serialPorts;
    String companyId;

    GenericIpConfig ipConfig;
}

And this is the request I am sending with POSTMAN:

{
    "updated":0,
    "enabled":true,
    "serialPorts":[],
    "companyId":"600",
    "companyCode":"0",
    "storeCode":"0",
    "ipConfig": {
        "connection_type":"ETHERNET",
        "port": "23",
        "port_ingenico": "",
        "ip": "192.168.10.55",
        "ip_ingenico": "",
        "id_ingenico": "",
        "active_ingenico": false,
        "lastPushTime": 0
    }
}

For some reason, I keep getting the following error:

JSON parse error: Unrecognized field \"connection_type\" (class it.igesa.monitoringsystem.model.mongo.device.config.GenericIpConfig), not marked as ignorable; nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field \"connection_type\" (class it.igesa.monitoringsystem.model.mongo.device.config.GenericIpConfig), not marked as ignorable (0 known properties: ]

I feel like my code is missing something, since this is the first time I am working with SpringBoot/MongoDB;

3 Answers 3

0

It looks as if Jackson can't recognise setter methods for fields, because they don't follow java naming conventions. Try fixing the unrecognised fields with this annotation - @JsonProperty("property_name_here"), by putting it on the setters.

You are also mixing them, some of your fields are named something_something, while others are somethingSomething, which is the standard java way. It's a good idea to pick one and stick to it for the project.

You should also read up on serialization with jackson documentation, annotation examples.

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

2 Comments

I tried it but it doesn't work. I keep getting the same error :/
@joe1531 Ok, can you update your question to show your complete classes - fields, getters, setters, constructors, and your exact attempt at fixing the error. I think more people should be able to give ideas like this.
0

Finally I found the solution. Defining setters and getters annotations for the nested class solved the problem.

Comments

0

I had an extra getter method in a class that I was reusing. It worked fine when I removed the extra getter. I hope you find this useful too. Thanks a lot.

Comments

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.