I'm implementing a search function in my application, where I'm searching for records that are in my database. I'm using ElasticSearch for this and I know that I will have to keep the database and the indices in sync. I'll take care of that on the application layer.
My question is more about querying ElasticSearch from my J2EE 7 application. I can get the JsonObject or JsonArray from a query and "manually parse" it using the Gson lib and its JsonObject and JsonArray classes, but that's hardly productive.
From what I've read, the best practice in parsing with GSON is to have a POJO that has the same structure as you Json objects. I could do that, but this POJO would be very similar to my JPA Entities, so I'd have the same information in two places, which would make maintenance harder. I haven't been able to get this to work seamlessly, but I'd like to try another approach.
So my question is, is it possible to map a json object to a JPA entity and more importantly, is this a good practice?
Here's my JSON (variable names can be changed, I know they don't match right now):
{
"vendorEcommerce": 1,
"Categories": {
"Sub": [
4,
8,
5
],
"Main": [
1,
2
]
},
"Countries": 1,
"vendorFeatured": 1,
"vendorWebsite": "www.johndoesserviceprovider.com",
"vendorEmail": "johndoe@gmail.com",
"vendorCreated": "2015-02-25T17:00:13.000Z",
"vendorName": "John Doe's Service Provider",
"vendorLocation": 1,
"vendorRating": 1,
"States": [
1,
2
],
"vendorUpdated": "2015-02-25T17:00:13.000Z",
"vendorPhone": "+11235551234",
"vendorDescription": "This is John Doe's Service Provider Description",
"vendorPromotion": "Oh yeah",
"vendorPrice": 3
}
And here's my JPA Entity (irrelevant information ommitted):
public class VendorEntity implements Serializable {
private static final long serialVersionUID = 1L;
private Integer vendorId;
private Date vendorCreated;
private Date vendorUpdated;
private String vendorName;
private String vendorWebsite;
private String vendorPhone;
private String vendorEmail;
private String vendorDescription;
private Boolean vendorEcommerce;
private Integer vendorRating;
private Integer vendorPrice;
private String vendorPromotion;
private Boolean vendorFeatured;
private LocationEntity location;
private List<ServiceCategoryEntity> categories;
private List<VendorCoverageEntity> coverages;
}