Hi
On 09/05/12 10:28, Govindaram PS wrote:
Problem is while reading back the same, derived elements are not recognized.
Is there any way to manage derived elements and ignoreNamespace at the same
time.
Not really. The idea behind 'ignoreNamespaces' is to make it easy for a
script to get the data it needs without worrying about prefixes.
As far as the JAXB is concerned it won't be able to process such a
payload unless the beans to be populated do not 'expect' the namespaces,
even if xsi:type were still included.
Cheers, Sergey
Thanks,
Govind
On Wed, May 9, 2012 at 2:46 PM, Sergey Beryozkin<[email protected]>wrote:
On 09/05/12 09:58, Govindaram PS wrote:
JsonProvider.writeTo fails to add xsitype when ignore namespace is set
true.
While reading the same it is failing to capture derived elements.
It does not make sense to include xsi:type when the namespaces are set to
be ignored
Cheers, Sergey
Test case:
@Test
public void testWriteReadDerivedNoNs() throws Exception {
JSONProvider<Base1> provider = new JSONProvider<Base1>();
provider.**setMarshallAsJaxbElement(true)**;
provider.setIgnoreNamespaces(**true);
provider.setWriteXsiType(true)**;
Base1 b = new Derived1("base", "derived");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
provider.writeTo(b, Base1.class, Base1.class,
new Annotation[0], MediaType.APPLICATION_JSON_**
TYPE,
new MetadataMap<String, Object>(), bos);
readBaseNoNs(bos.toString());
}
private void readBaseNoNs(String data) throws Exception {
JSONProvider<Base1> provider = new JSONProvider<Base1>();
provider.**setUnmarshallAsJaxbElement(**true);
provider.setIgnoreNamespaces(**true);
ByteArrayInputStream is = new ByteArrayInputStream(data.**
getBytes());
Base1 base = provider.readFrom(
Base1.class, Base1.class,
new Annotation[0], MediaType.APPLICATION_JSON_**
TYPE,
new MetadataMap<String, String>(), is);
assertEquals("base", base.getBase1Field());
Derived1 derived = (Derived1)base;
}
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com