Does anybody know how to attach custom XmlAdapter
to objects contained in heterogenous list (like List)?
For example - suppose we have a container class with a list of miscelaneous objects:
@XmlRootElement(name = "container")
public class Container {
private List<Object> values = new ArrayList<Object>();
@XmlElement(name = "value")
public List<Object> getValues() {
return values;
}
public void setValues(List<Object> values) {
this.values = values;
}
}
If we put String
-s, Integer
-s and so on they will be mapped by default. Now suppose we want to put a custom object:
public class MyObject {
//some properties go here
}
The obvious solution is to write a custom adapter:
public class MyObjectAdapter extends XmlAdapter<String, MyObject> {
//marshalling/unmarshalling
}
But unfortunately it doesn't work with package-level @XmlJavaTypeAdapter
- adapter just never called so marhalling fails.
And I can't apply it to getValues()
directly because there can be other types of objects.
@XmlJavaTypeAdapter
only works if I have a field of MyObject type in Container (also with package-level annotaton):
public class Container {
private MyObject myObject;
}
But this is not what I want - I want a list of arbitrary objects. I'm using standard Sun's JAXB implementation:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.3-1</version>
</dependency>
Any ideas how to do the mapping?
P.S.: One small clarification - I'd like to avoid annotating MyObject
with JAXB annotations. It may be a class from third-party library which is not under my control. So any changes should be outside of MyObject
.
You need to do:
$('#menu') <-- note the # sign
in your selectors.... Otherwise it looks like it should work OK
API Reference: jQuery ID Selector
To address your edit:
Element state is not automatically preserved between page loads. The browser doesn't look for "the same element" and try to make it appear the same. If you want the menu to remain open, you need to persist some data (whether through postback data or (I would recommend) some browser side state saving (e.g. localStorage
)) and handle it manually in your menu code
Oh....rereading your question I think it might be simpler than that....
On page load, you could do something like:
$('[href=' + window.location.path + ']').addClass('active');
the window.location.path
would likely need some pre-processing before the selector though to handle extra url parameters and variations of the path (e.g. ./index.html
and index.html
) in the href. However, note the various types of matching available with the attribute selector...namely *=
...might make your href matching a lot easier...but I'm not gonna write all your code =0D
API Reference: jQuery Attribute Selector