I have a given set of classes to unmarshall a xml into an object tree. Now I get a extended xml and want to replace one class in the object tree with an extended version.
You should do XML schema versioning instead of this, however it is difficult to do it well. There is a pdf in the linked article, you should read it.
I did the "Option 3 Change the schema's targetNamespace" in the past, in this way, you can do the following:
you have different targetNamespaces for every version:
targetNamespace="http://www.exampleSchema.com/v1.0"
targetNamespace="http://www.exampleSchema.com/v1.1"
...
and you can generate the necessary JAXB classes for each namespace in different group:
com.example.schema.generated.v10
com.example.schema.generated.v11
...
From here it is up to you how to try to read it:
(of course, you have to handle each version separately after unmarshalling, which is not necessarily bad)
OR
you can decide so that you are using only 1 schema, and one can only extend the schema with optional (minOccurs="0") elements, it is ugly, and has some limitations, but sometimes it is enough.
OR
Or, you can do it in a different way: you can use another XML framework, that supports schema versioning, like this one: JMRI or JiBX (They are not necessary current or actively developed, just wanted to show some examples. What I really wanted to link is an another one, but unfortunately I forgot its name).