0

I have an object having an attribute of type map, but I want this map to be serialized to a list, containing only the values of this map.

I could do this by other means (for example, by making the map transient, adding a couple of setter/getter returning the values of the map and serializing this list) but I was wondering if there was a way to customize SimpleXml to get this result.

1 Answer 1

1

Like in your other question is a good idea to implement a Converter.

Here are some aspects:

  1. Implement a Converter for the object
    1. Retrieve the attribute map
    2. Iterate over it an write it's content to the OutputNode or write them into a liste and serialize this instead
  2. Set Converter and AnnotationStrategy
  3. Serialize

Please see also:

However, please give us some more informations (like structure of the class and expected output xml).

Sign up to request clarification or add additional context in comments.

3 Comments

I will use your answer to my other question to try to solve my problem. If it is not sufficient, I will come back with further explanation. Thank you.
In fact the problem is that it seems you need to rewrite the full serialization process. You don't have a way to say "I want to serialize this class exactly like the default settings,except for this part". For the complex classes, rewriting a Converter can take some time.
You can set a Converter only for the element you need to serialize while the other parts are serialized as default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.