Created
November 20, 2012 21:58
-
-
Save cowtowncoder/4121515 to your computer and use it in GitHub Desktop.
Immutable POJO that Just Works with Jackson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This class works just fine, although you might not think so at first glance. | |
* Serialization is easy -- just uses getters, after all -- but how about deser? | |
* Turns out that: | |
* | |
* (a) Since Jackson auto-detects private fields (as long as something else indicates | |
* presence of a property; here getters do it), and | |
* (b) JDK (1.5+) allows Reflection to force setting of a 'final' value | |
* | |
* it... well, works. Try it for fun! | |
*/ | |
public class ImmutaBean | |
{ | |
private int x, y; | |
public int getX() { return x; } | |
public int getY() { return y; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment