I want to use ORMLite to query data from SQLite and store it in Java class, then convert this class to JSON using Jackson JSON library and send it through HTTP. I also want to do opposite - get data from server in JSON and convert it to Java class and save this class to SQLite using ORMLite.
Can I do this using one class per table for both ORMLite and Jackson?
Yes you can, why not? you can convert to json any java object you want
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(object);;
ORMLite create entity, which is java object so.
@DatabaseTable(tableName = "accounts")
public class Account {
@DatabaseField(id = true)
private String name;
@DatabaseField(canBeNull = false)
private String password;
...
Account() {
// all persisted classes must define a no-arg constructor with at least package visibility
}
...
}
yes you can.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With