By W.ZH Apr 2015
1. install the JDK to the /usr/local/java just get JDK package, unzip it and copy all content to this folder or nay folder you want to put in. 2. change env when system start for all user: cd /etc/profile.d create file of myenv.sh like this: (need sudo if you are not root) cat myenv.sh
3. change the ubuntu default setting about the java:
you get something like this: There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ———————————————————— * 0 1 2 /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java 1061 manual mode Press enter to keep the current choice[*], or type selection number:
|
Monthly Archives: April 2015
A special case for de-serialize Polymorphic class by Jackson
A special case for de-serialize Polymorphic class by Jackson
By WZh Apr 2015 A very good article about the de-serialize the data in Jackson from Json to JAVA is already at this article But a special case we have met is not in that article. Input json sample: // { “type”:”dog”, // “animal”: // {“name”:”Spike”, // “breed”:”mutt”, // “leash_color”:”red”} } or // { “type”:”cat”, // “animal”: // {“name”:”Fluffy”, // “favorite_toy”:”spider ring”} // } This means type is not inside the abstract class itself, type is controlled by parent class fields and also we want to use getter and setter in the parent class for “type” in other java code, to type must be cleared defined at Zoo class as Java field. Here is the solution after research! class Zoo { private String type; private Animal animal; @JsonTypeId public String getType() { return type; } public void setType(String type) { this.type = type; } @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = “type”) @JsonSubTypes({ @Type(value = Cat.class, name = “cat”), @Type(value = Dog.class, name = “dog”) }) public void setAnimal ( Animal value) { this.animal = value; } public Animal getAnimal () { return animal; } } abstract class Animal { } class Dog extends Animal { public String name; public String breed; public String leashColor; } class Cat extends Animal { public String name; public String favoriteToy; } the most important thing in the code is :
|