JUnit tests for POJOs

The rule in TDD is “Test everything that could possibly break” Can a getter break? Generally not, so I don’t bother to test it. Besides, the code I do test will certainly call the getter so it will be tested. My personal rule is that I’ll write a test for any function that makes a … Read more

How to map the result set of a JPA NativeQuery to a POJO using SqlResultSetMapping

@SqlResultSetMapping annotation should not be put on a POJO. Put it at (any) @Entity class. “Unknown SqlResultSetMapping [foo]” tells you, that JPA provider doesn’t see any mapping under name ‘foo’. Please see another answer of mine for the correct example JPA- Joining two tables in non-entity class

Jackson JSON Deserialization with Root Element

edit: this solution only works for jackson < 2.0 For your case there is a simple solution: You need to annotate your model class with @JsonRootName(value = “user”); You need to configure your mapper with om.configure(Feature.UNWRAP_ROOT_VALUE, true); (as for 1.9) and om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); (for version 2). That’s it! @JsonRootName(value = “user”) public static class User … Read more

JSON Post request for boolean field sends false by default

Remember that Jackson, by default, determines the property name from either the getter or setter (the first that matches). To deserialize an object of type POJOUserDetails, Jackson will look for three properties public void setFirstName(String firstName) { public void setLastName(String lastName) { public void setActive(boolean isActive) { in the JSON. These are basically firstName, lastName, … Read more