Say that I have following objects:
public class ComplexJacksonObject extends BaseJsonObject {
public int Start;
public int Count;
public Person MyPerson;
public class Person extends BaseJsonObject {
public String Firstname;
public String Lastname;
public Address Where;
}
public class Address extends BaseJsonObject {
public String Street;
public int Number;
}
}
Obviously when I request JSON of this with Jackson I get something like:
public String toJson(ComplexJacksonObject obj) {
try {
return generateMapper().writeValueAsString(obj);
} catch (JsonProcessingException e) {
e.printStackTrace();
return null;
}
}
// returned: {"MyPerson":{"Firstname":"First","Lastname":"Last","Where":{"Street":"Street","Number":15}},"Count":1,"Start":2}
However what I need for QueryString is that top property pairs are converted to Key=Value& format, so something like:
MyPerson={"Firstname":"First","Lastname":"Last","Where":{"Street":"Street","Number":15}}&Count=1&Start=2
Plus of course MyPerson=[This_Part_Needs_To_Be_Url_Encoded].
Is there any generic method in Jackson that would do this for me automatically? Or will I be forced to come up with something my own? Some String replacement regex? Any ideas?