How to upgrade the JAVA version at ubuntu

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 like this: (need sudo if you are not root)


            export JAVA_HOME=/usr/local/java

            export PATH=$PATH:$JAVA_HOME/bin

3. change the ubuntu default setting about the java:


    sudo update-alternatives --install /usr/bin/java java ${JAVA_HOME%*/}/bin/java 20000

    sudo update-alternatives --install /usr/bin/javac javac ${JAVA_HOME%*/}/bin/javac 20000

    update-alternatives --config java

you get something like this:

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                           Priority   Status


* 0
/usr/local/java/bin/java                  20000     auto mode

/usr/local/java/bin/java                  20000     manual mode

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:

    java -version

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:

//   {


//     “animal”:

//           {“name”:”Spike”,

// “breed”:”mutt”,

//            “leash_color”:”red”}



//   {


//     “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;  


public String getType() {

return type;


public void setType(String type) {

this.type = type;



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 :

  1. @JsonTypeId set to getter for “type” and let the jackson do not create duplicate “type” in the json
  2. @JsonTypeInfo defined with JsonTypeInfo.As.EXTERNAL_PROPERTY to let the Animal class can be controlled by the external property “type” to do the Polymorphic
  3. @JsonTypeInfo is put to the setter of the abstract class to contorl the Polymorphic