I am a new Java developer and working on an ERP Project. I went through the codebase of my project and found some interesting and pretty complex coding structure.
The entire application was developed on pure JPA and very little use of spring boot’s own interfaces, annotations, and methods. For example, no JPARepository interface was used at all. The @Repository is a class here and they used Jackson data binding for crud operation.
For example, this is repository class looks like,
`@Repository
public Response save(String empRegistration) {
JSONObject json = new JSONObject(empRegistration); // from android library
String empReg= Def.getString(json, "empReg");
EmpRegistration empRegistration = new EmpRegistration ();
empRegistration = objectMapperReadValue(empReg, EmpRegistration.class);
Response response = baseOnlySave(EmpRegistration); // baseOnlySave is the base save method written in pure JPA.
return response;
}`
This is objectMapperReadValue method
`default T objectMapperReadValue(String content, Class valueType) {
ObjectMapper objectMapper = new ObjectMapper();
try {
return objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).readValue(content,
valueType);
} catch (JsonParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
// return null;
}`
What I would basically do
Public Response save (Employee emp) { empRepository.save(emp); return response;}
So, my question is, do we really need to use JSONObject and objectMapper class to save an object while developing Enterprise application in spring boot?
Alex Jones is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.