[Simple-support] Maps with inline values; default values
Brought to you by:
niallg
|
From: Paul J. <pa...@pa...> - 2014-02-14 12:31:41
|
Hi,
Thanks for the tips so far. For most of the issues I raised I now have
workarounds that will suffice. And I'm going to investigate JSON
serialisation shortly.
However, there are two issues that I still need some help with:
1) Maps with inline values
If I have a field like this:
@ElementMap(inline=true, attribute=true)
Map<String,VarInfo> sinks = new HashMap<String,VarInfo>();
It produces XML like this:
<entry key="xss">
<varInfo>
<field>jim</field>
<field2>bob</field2>
</varInfo>
</entry>
I want XML like this:
<varInfo key="xss">
<field>jim</field>
<field2>bob</field2>
</varInfo>
I did propose a hack to write this correctly, but it breaks reading - and I
can't see how to fix that. Also, there is a teasing note in Entry.java
saying "value objects can be written inline if desired" - so I think there
is a way to do it, I've just not figured it out yet.
2) Default values
I want to have a field like:
@Attribute(default=true)
boolean myField;
Now, when writing, if myField is true, then I want to skip the field. And
when reading, if the attribute it missing, I want to use the default value.
Note that "empty" does NOT have these semantics.
I realise this is probably a new feature, but it would be extremely helpful
to me, in keeping the generated XML concise. I have considered putting this
at other parts in my app (e.g. just letting myField be null and handling
that appropriately) but it really would help to have Simple do this.
Any input would be appreciated,
Paul
|