Re: [Simple-support] NullPointerException for similar Element Names with different @Paths
Brought to you by:
niallg
|
From: Gupta, A. A <ami...@rb...> - 2012-08-10 18:02:07
|
If you run this code - it will replicate the scenario. Note that other elements such as 'type' and 'role' are working fine. Only sourcesystem is misbehaving.
If you rename sourceSystem to sourceSystem-remove - it would run fine.
Thanks,
--------------------------------------------------------------------------------
package test.simple.scenario.path;
import java.io.StringWriter;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Namespace;
import org.simpleframework.xml.Path;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
@Root(name="header")
public class TradeHeader {
@Element(name = "sourceSystem")
@Path("tradeIdentifier/tradeKey")
@Namespace
private String tradeKeySourceSystem = "VALUE";
@Attribute(name = "id")
@Path("book")
private String bookId = "BOOK";
@Element(name = "code")
@Path("book/identifier")
@Namespace
private String bookCode = "code";
@Element(name = "sourceSystem")
@Path("book/identifier")
@Namespace
private String bookSourceSystem = "VALUE";
@Element(name = "type")
@Path("book/identifier")
@Namespace
private String bookType = "SHORT_NAME";
@Element(name = "role")
@Path("book")
@Namespace
private String bookRole = "VALUE";
@Attribute(name = "id")
@Path("trader")
private String traderId = "TID";
@Element(name = "code")
@Path("trader/identifier")
@Namespace
private String traderCode = "tCode";
@Element(name = "sourceSystem")
@Path("trader/identifier")
@Namespace
private String traderSourceSystem = "VALUE";
@Element(name = "type")
@Path("trader/identifier")
@Namespace
private String traderType = "SHORT_NAME";
@Element(name = "role")
@Path("trader")
@Namespace
private String traderRole = "VALUE";
public static void main(String[] args) throws Exception {
Serializer serializer = new Persister();
StringWriter writer = new StringWriter();
TradeHeader header = new TradeHeader();
serializer.write(header, writer);
String data = writer.getBuffer().toString();
System.out.println(data);
}
}
-----Original Message-----
From: Niall Gallagher [mailto:gal...@ya...]
Sent: 2012, August, 10 12:58 PM
To: sim...@li...; Gupta, Amit A
Subject: Re: [Simple-support] NullPointerException for similar Element Names with different @Paths
Can you provide a test, I find this unlikely..but its possible I guess. Some code to repeat this would be good.
--- On Fri, 10/8/12, amit.shipra <ami...@rb...> wrote:
> From: amit.shipra <ami...@rb...>
> Subject: Re: [Simple-support] NullPointerException for similar Element
> Names with different @Paths
> To: sim...@li...
> Received: Friday, 10 August, 2012, 6:17 AM
>
> In the XML Message 'sourceSystem' is at multiple places. I overlooked
> in my haste. When I tried name="sourceSystem[1]" the actual tags were
> changed to <ns0:sourceSystem[1]>value</sourceSystem[1]>.
>
> Issue remains. Please help.
>
> Amit-G.
>
>
>
> Robert Massaioli-2 wrote:
> >
> > You just said previously that you had solved the
> problem? Is that not the
> > case?
> >
> > On Fri, Aug 10, 2012 at 11:04 PM, amit.shipra
> > <ami...@rb...>wrote:
> >
> >>
> >> Could someone please help with this issue. Let me
> know if I am doing
> >> anything
> >> wrong here?? :-/
> >>
> >>
> >> amit.shipra wrote:
> >> >
> >> > Hi there,
> >> >
> >> > XML looks like:
> >> >
> >> >
> <ns0:book id="BOOK">
> >> >
> <ns0:identifier>
> >> >
>
> <ns0:sourceSystem>DTCC</ns0:sourceSystem>
> >> >
> </ns0:identifier>
> >> >
> </ns0:book>
> >> >
> <ns0:trader
> id="ID_EXECUTING_TRADER">
> >> >
> <ns0:identifier>
> >> >
>
> <ns0:sourceSystem>NYSE</ns0:sourceSystem>
> >> >
> </ns0:identifier>
> >> >
> </ns0:trader>
> >> >
> >> >
> >> > and my JAVA code (for sourceSystem Element)
> is:
> >> >
> >> >
> @Element(name="sourceSystem")
> >> >
> @Path("ns0:book/ns0:identifier")
> >> > private String
> bookSourceSystem="system1";
> >> >
> >> >
> >> >
> @Element(name="sourceSystem")
> >> >
> @Path("ns0:trader/ns0:identifier")
> >> > private String
> traderSourceSystem="system2";
> >> >
> >> >
> >> > However, I am getting the
> NullPointerException:
> >> >
> >> > StackTrace:
> >> > Exception in thread "main"
> java.lang.NullPointerException
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.InstantiatorBuilder.register(Instantiator
> Builder.java:461)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.InstantiatorBuilder.register(Instantiator
> Builder.java:433)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.StructureBuilder.process(StructureBuilder
> .java:283)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.StructureBuilder.process(StructureBuilder
> .java:259)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.StructureBuilder.process(StructureBuilder
> .java:200)
> >> > at
> org.simpleframework.xml.core.Scanner.field(Scanner.java:511)
> >> > at
> org.simpleframework.xml.core.Scanner.scan(Scanner.java:395)
> >> > at
> org.simpleframework.xml.core.Scanner.<init>(Scanner.java:104)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.ScannerFactory.getInstance(ScannerFactory
> .java:77)
> >> > at
> >>
> org.simpleframework.xml.core.Support.getScanner(Support.java:203)
> >> > at
> >>
> org.simpleframework.xml.core.Source.getScanner(Source.java:271)
> >> > at
> org.simpleframework.xml.core.Source.getCaller(Source.java:300)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.Composite.writeReplace(Composite.java:114
> 7)
> >> > at
> >>
> org.simpleframework.xml.core.Composite.writeUnion(Composite.java:1124)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.Composite.writeElements(Composite.java:10
> 98)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.Composite.writeSection(Composite.java:100
> 4)
> >> > at
> >>
> org.simpleframework.xml.core.Composite.write(Composite.java:975)
> >> > at
> >>
> org.simpleframework.xml.core.Composite.write(Composite.java:952)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.Composite.writeElement(Composite.java:125
> 6)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.Composite.writeElement(Composite.java:123
> 9)
> >> > at
> >>
> org.simpleframework.xml.core.Composite.writeUnion(Composite.java:1127)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.Composite.writeElements(Composite.java:10
> 98)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.Composite.writeSection(Composite.java:100
> 4)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.Composite.writeElements(Composite.java:10
> 87)
> >> > at
> >> >
> >>
> org.simpleframework.xml.core.Composite.writeSection(Composite.java:100
> 4)
> >> > at
> >>
> org.simpleframework.xml.core.Composite.write(Composite.java:975)
> >> > at
> >>
> org.simpleframework.xml.core.Composite.write(Composite.java:952)
> >> > at
> >>
> org.simpleframework.xml.core.Traverser.write(Traverser.java:236)
> >> > at
> >>
> org.simpleframework.xml.core.Traverser.write(Traverser.java:208)
> >> > at
> >>
> org.simpleframework.xml.core.Traverser.write(Traverser.java:186)
> >> > at
> >>
> org.simpleframework.xml.core.Persister.write(Persister.java:1180)
> >> > at
> >>
> org.simpleframework.xml.core.Persister.write(Persister.java:1162)
> >> > at
> >>
> org.simpleframework.xml.core.Persister.write(Persister.java:1140)
> >> > at
> >>
> org.simpleframework.xml.core.Persister.write(Persister.java:1259)
> >> > at
> >>
> org.simpleframework.xml.core.Persister.write(Persister.java:1241)
> >> > at
> >>
> org.simpleframework.xml.core.Persister.write(Persister.java:1222)
> >> > at
> >>
> org.simpleframework.xml.core.Persister.write(Persister.java:1201)
> >> >
> >> >
> >> > Source code block:
> >> >
> >> > private void register(Label
> label, LabelMap map) throws Exception {
> >> > String name =
> label.getName();
> >> > String path =
> label.getPath();
> >> >
> >> >
> if(map.containsKey(name)) {
> >> > Label
> current = map.get(name); <-- THIS RETURNS current AS
> >> NULL.
> >> > String key =
> current.getPath();
> >> >
> >> >
> >> > Could we have only one Element even if @Paths
> are different? Struck
> >> around
> >> > this for long. Is there a work around?
> >> >
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://old.nabble.com/NullPointerException-for-similar-Element-Name
> >> s-with-different-%40Paths-tp34277238p34281760.html
> >> Sent from the Simple XML Serialization mailing list
> archive at
> >> Nabble.com.
> >>
> >>
> >>
> >>
> ----------------------------------------------------------------------
> --------
> >> Live Security Virtual Conference
> >> Exclusive live event will cover all the ways
> today's security and
> >> threat landscape has changed and how IT managers
> can respond. Discussions
> >> will include endpoint security, mobile security and
> the latest in malware
> >> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> >> _______________________________________________
> >> Simple-support mailing list
> >> Sim...@li...
> >> https://lists.sourceforge.net/lists/listinfo/simple-support
> >>
> >
> >
> ----------------------------------------------------------------------
> --------
> > Live Security Virtual Conference
> > Exclusive live event will cover all the ways today's
> security and
> > threat landscape has changed and how IT managers can
> respond. Discussions
> > will include endpoint security, mobile security and the
> latest in malware
> > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> > _______________________________________________
> > Simple-support mailing list
> > Sim...@li...
> > https://lists.sourceforge.net/lists/listinfo/simple-support
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/NullPointerException-for-similar-Element-Names-w
> ith-different-%40Paths-tp34277238p34281810.html
> Sent from the Simple XML Serialization mailing list archive at
> Nabble.com.
>
>
> ----------------------------------------------------------------------
> --------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond.
> Discussions will include endpoint security, mobile security and the
> latest in malware threats.
> http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
>
_______________________________________________________________________
This email is intended only for the use of the individual(s) to whom it is addressed and may be privileged and confidential.
Unauthorised use or disclosure is prohibited. If you receive This e-mail in error, please advise immediately and delete the original message.
This message may have been altered without your or our knowledge and the sender does not accept any liability for any errors or omissions in the message.
Ce courriel est confidentiel et protégé. L'expéditeur ne renonce pas aux droits et obligations qui s'y rapportent.
Toute diffusion, utilisation ou copie de ce message ou des renseignements qu'il contient par une personne autre que le (les) destinataire(s) désigné(s) est interdite.
Si vous recevez ce courriel par erreur, veuillez m'en aviser immédiatement, par retour de courriel ou par un autre moyen.
|