Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Camel - Json to POJO automatic data type conversion?

Can Camel be configured to automatically handle data type conversions from JSON to a POJO. For example...looking at Camels website we have the following JSON example: { "id" : 123, "first_name" : "Donald" "last_name" : "Duck" }

and corresponding POJO

public class PersonPojo {

private int id;
private String firstName;
private String lastName;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

}

but does Camel have automatic data type converters where I could set the POJO up to have the ID field unmarshalled to a String object, rather than an int?

like image 520
deanmau5 Avatar asked Jul 04 '26 11:07

deanmau5


1 Answers

Yes, this can be achieved with TypeConverters http://camel.apache.org/type-converter.html

You can also perform this explicitly with the dataFormats element too http://camel.apache.org/data-format.html

Hope that helps :)

like image 57
AlanFoster Avatar answered Jul 07 '26 02:07

AlanFoster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!