[jxpath] How to add an entry to a list?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[jxpath] How to add an entry to a list?

KARR, DAVID (ATTSI)
If a property in a bean I'm trying to manipulate with jxpath is a List, how do I set a value in an entry of that list?

I read the info at "Modifying Object Graphs", but it's still not clear from this how I would do this.

I've figured out how to get the list created, either with an explicit "setValue()", or with a "createPathAndSetValue()" along with a factory and createObject() method set to look for that property, but if I try to set a value into the list, it fails apparently because the list is still zero size.

The only way I can hack this to work is to initialize the list property to an ArrayList with the required number of dummy elements already added to it, so the subscript reference works.

I'm using JXPath so that I can write tests with a little less boilerplate and focus on pure business logic.  Ideally, I'd like JXPath (or perhaps a factory) to do the "obvious stuff".


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [jxpath] How to add an entry to a list?

Bruno P. Kinoshita-3
Hi David,

Do you have some code you could share? Maybe looking at your code others (I would try as well, but can't promise will know how to help) might be able to help.

Cheers
Bruno


________________________________
From: "KARR, DAVID" <[hidden email]>
To: Commons Users List <[hidden email]>
Sent: Wednesday, 14 June 2017 6:11 AM
Subject: [jxpath] How to add an entry to a list?



If a property in a bean I'm trying to manipulate with jxpath is a List, how do I set a value in an entry of that list?


I read the info at "Modifying Object Graphs", but it's still not clear from this how I would do this.


I've figured out how to get the list created, either with an explicit "setValue()", or with a "createPathAndSetValue()" along with a factory and createObject() method set to look for that property, but if I try to set a value into the list, it fails apparently because the list is still zero size.


The only way I can hack this to work is to initialize the list property to an ArrayList with the required number of dummy elements already added to it, so the subscript reference works.


I'm using JXPath so that I can write tests with a little less boilerplate and focus on pure business logic.  Ideally, I'd like JXPath (or perhaps a factory) to do the "obvious stuff".



---------------------------------------------------------------------

To unsubscribe, e-mail: [hidden email]

For additional commands, e-mail: [hidden email]

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: [jxpath] How to add an entry to a list?

KARR, DAVID (ATTSI)
> -----Original Message-----
> From: Bruno P. Kinoshita [mailto:[hidden email]]
> Sent: Wednesday, June 14, 2017 3:18 AM
> To: Commons Users List <[hidden email]>
> Subject: Re: [jxpath] How to add an entry to a list?
>
> Hi David,
>
> Do you have some code you could share? Maybe looking at your code others
> (I would try as well, but can't promise will know how to help) might be
> able to help.

Thanks for replying.  I posted more detailed code samples on SO: https://stackoverflow.com/questions/44530112/how-to-get-jxpath-to-cleanly-set-list-collection-entries .

> ________________________________
> From: "KARR, DAVID" <[hidden email]>
> To: Commons Users List <[hidden email]>
> Sent: Wednesday, 14 June 2017 6:11 AM
> Subject: [jxpath] How to add an entry to a list?
>
>
>
> If a property in a bean I'm trying to manipulate with jxpath is a List,
> how do I set a value in an entry of that list?
>
>
> I read the info at "Modifying Object Graphs", but it's still not clear
> from this how I would do this.
>
>
> I've figured out how to get the list created, either with an explicit
> "setValue()", or with a "createPathAndSetValue()" along with a factory
> and createObject() method set to look for that property, but if I try to
> set a value into the list, it fails apparently because the list is still
> zero size.
>
>
> The only way I can hack this to work is to initialize the list property
> to an ArrayList with the required number of dummy elements already added
> to it, so the subscript reference works.
>
>
> I'm using JXPath so that I can write tests with a little less
> boilerplate and focus on pure business logic.  Ideally, I'd like JXPath
> (or perhaps a factory) to do the "obvious stuff".
>
>
>
> ---------------------------------------------------------------------
>
> To unsubscribe, e-mail: [hidden email]
>
> For additional commands, e-mail: [hidden email]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: [jxpath] How to add an entry to a list?

Bruno P. Kinoshita-3
In reply to this post by KARR, DAVID (ATTSI)
Thanks for the link David. Posted a complete reply there, but here's the TL;DR.

The only way I found of doing that, was by pre-populating your list with an empty element. That way, /numbers[1] calls List#set(0, "123") with no exceptions.

Hope that helps
Bruno



________________________________
From: "KARR, DAVID" <[hidden email]>
To: Commons Users List <[hidden email]>; Bruno P. Kinoshita <[hidden email]>
Sent: Thursday, 15 June 2017 3:13 AM
Subject: RE: [jxpath] How to add an entry to a list?



> -----Original Message-----
> From: Bruno P. Kinoshita [mailto:[hidden email]]
> Sent: Wednesday, June 14, 2017 3:18 AM
> To: Commons Users List <[hidden email]>
> Subject: Re: [jxpath] How to add an entry to a list?
>
> Hi David,
>
> Do you have some code you could share? Maybe looking at your code others
> (I would try as well, but can't promise will know how to help) might be
> able to help.

Thanks for replying.  I posted more detailed code samples on SO: https://stackoverflow.com/questions/44530112/how-to-get-jxpath-to-cleanly-set-list-collection-entries .

> ________________________________
> From: "KARR, DAVID" <[hidden email]>
> To: Commons Users List <[hidden email]>
> Sent: Wednesday, 14 June 2017 6:11 AM
> Subject: [jxpath] How to add an entry to a list?
>
>
>
> If a property in a bean I'm trying to manipulate with jxpath is a List,
> how do I set a value in an entry of that list?
>
>
> I read the info at "Modifying Object Graphs", but it's still not clear
> from this how I would do this.
>
>
> I've figured out how to get the list created, either with an explicit
> "setValue()", or with a "createPathAndSetValue()" along with a factory
> and createObject() method set to look for that property, but if I try to
> set a value into the list, it fails apparently because the list is still
> zero size.
>
>
> The only way I can hack this to work is to initialize the list property
> to an ArrayList with the required number of dummy elements already added
> to it, so the subscript reference works.
>
>
> I'm using JXPath so that I can write tests with a little less
> boilerplate and focus on pure business logic.  Ideally, I'd like JXPath
> (or perhaps a factory) to do the "obvious stuff".
>
>
>
> ---------------------------------------------------------------------
>
> To unsubscribe, e-mail: [hidden email]
>
> For additional commands, e-mail: [hidden email]

>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]

Т���������������������������������������������������������������������ХF�V�7V'67&�&R�R���âW6W"�V�7V'67&�&T6�����2�6�R��&pФf�"FF�F����6����G2�R���âW6W"ֆV�6�����2�6�R��&pР

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: [jxpath] How to add an entry to a list?

KARR, DAVID (ATTSI)
> -----Original Message-----
> From: Bruno P. Kinoshita [mailto:[hidden email]]
> Sent: Thursday, June 15, 2017 2:51 AM
> To: Commons Users List <[hidden email]>
> Subject: Re: [jxpath] How to add an entry to a list?
>
> Thanks for the link David. Posted a complete reply there, but here's the
> TL;DR.
>
> The only way I found of doing that, was by pre-populating your list with
> an empty element. That way, /numbers[1] calls List#set(0, "123") with no
> exceptions.

Ok.  Does it seem like mitigating this might be a reasonable enhancement for JXPath?  I don't know yet how it would work, but I see it as a flag that when on, would simply deal with this by extending the list automatically.

> ________________________________
> From: "KARR, DAVID" <[hidden email]>
> To: Commons Users List <[hidden email]>; Bruno P. Kinoshita
> <[hidden email]>
> Sent: Thursday, 15 June 2017 3:13 AM
> Subject: RE: [jxpath] How to add an entry to a list?
>
>
>
> > -----Original Message-----
> > From: Bruno P. Kinoshita [mailto:[hidden email]]
> > Sent: Wednesday, June 14, 2017 3:18 AM
> > To: Commons Users List <[hidden email]>
> > Subject: Re: [jxpath] How to add an entry to a list?
> >
> > Hi David,
> >
> > Do you have some code you could share? Maybe looking at your code
> others
> > (I would try as well, but can't promise will know how to help) might
> be
> > able to help.
>
> Thanks for replying.  I posted more detailed code samples on SO:
> https://urldefense.proofpoint.com/v2/url?u=https-
> 3A__stackoverflow.com_questions_44530112_how-2Dto-2Dget-2Djxpath-2Dto-
> 2Dcleanly-2Dset-2Dlist-2Dcollection-2Dentries&d=DwIFaQ&c=LFYZ-
> o9_HUMeMTSQicvjIg&r=OsTemSXEn-xy2uk0vYF_EA&m=nfT2LEhdW7RV4azBV5z7cO-
> vMKzYetKiHBtDCkt0CoI&s=AXR_qT2s9pltw3Q7IPZwifyv91V3YxSISo5Jt_B3KE4&e=  .
>
> > ________________________________
> > From: "KARR, DAVID" <[hidden email]>
> > To: Commons Users List <[hidden email]>
> > Sent: Wednesday, 14 June 2017 6:11 AM
> > Subject: [jxpath] How to add an entry to a list?
> >
> >
> >
> > If a property in a bean I'm trying to manipulate with jxpath is a
> List,
> > how do I set a value in an entry of that list?
> >
> >
> > I read the info at "Modifying Object Graphs", but it's still not clear
> > from this how I would do this.
> >
> >
> > I've figured out how to get the list created, either with an explicit
> > "setValue()", or with a "createPathAndSetValue()" along with a factory
> > and createObject() method set to look for that property, but if I try
> to
> > set a value into the list, it fails apparently because the list is
> still
> > zero size.
> >
> >
> > The only way I can hack this to work is to initialize the list
> property
> > to an ArrayList with the required number of dummy elements already
> added
> > to it, so the subscript reference works.
> >
> >
> > I'm using JXPath so that I can write tests with a little less
> > boilerplate and focus on pure business logic.  Ideally, I'd like
> JXPath
> > (or perhaps a factory) to do the "obvious stuff".
> >
> >
> >
> > ---------------------------------------------------------------------
> >
> > To unsubscribe, e-mail: [hidden email]
> >
> > For additional commands, e-mail: [hidden email]
>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
>
> Т���������������������������������������������������������������������ХF
> �V�7V'67&�&R�R���âW6W"�V�7V'67&�&T6�����2�6�R��&pФf�"FF�F����6����G2�R��
> �âW6W"ֆV�6�����2�6�R��&pР
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: [jxpath] How to add an entry to a list?

Bruno P. Kinoshita-3
>Ok.  Does it seem like mitigating this might be a reasonable enhancement for JXPath?  I don't know yet how it would work, but I see it as a flag that when on, would simply deal with this by extending the list automatically.

I am not sure. You can file an issue for that if you'd like. From what I understood reading some parts of the code (e.g. ValueUtils#setValue) this is by design. You are using a List, so that worked in your case. But should you had another collection, I believe you would get a UnsupportedOperationException.


There may be other approaches to solving this issue that I am not aware of. But in case you build a good argument in your issue in JIRA, it may be implemented in jxpath.

Cheers
Bruno

________________________________
From: "KARR, DAVID" <[hidden email]>
To: Commons Users List <[hidden email]>; Bruno P. Kinoshita <[hidden email]>
Sent: Friday, 16 June 2017 3:37 AM
Subject: RE: [jxpath] How to add an entry to a list?



> -----Original Message-----
> From: Bruno P. Kinoshita [mailto:[hidden email]]
> Sent: Thursday, June 15, 2017 2:51 AM
> To: Commons Users List <[hidden email]>
> Subject: Re: [jxpath] How to add an entry to a list?
>
> Thanks for the link David. Posted a complete reply there, but here's the
> TL;DR.
>
> The only way I found of doing that, was by pre-populating your list with
> an empty element. That way, /numbers[1] calls List#set(0, "123") with no
> exceptions.

Ok.  Does it seem like mitigating this might be a reasonable enhancement for JXPath?  I don't know yet how it would work, but I see it as a flag that when on, would simply deal with this by extending the list automatically.

> ________________________________
> From: "KARR, DAVID" <[hidden email]>
> To: Commons Users List <[hidden email]>; Bruno P. Kinoshita
> <[hidden email]>
> Sent: Thursday, 15 June 2017 3:13 AM
> Subject: RE: [jxpath] How to add an entry to a list?
>
>
>
> > -----Original Message-----
> > From: Bruno P. Kinoshita [mailto:[hidden email]]
> > Sent: Wednesday, June 14, 2017 3:18 AM
> > To: Commons Users List <[hidden email]>
> > Subject: Re: [jxpath] How to add an entry to a list?
> >
> > Hi David,
> >
> > Do you have some code you could share? Maybe looking at your code
> others
> > (I would try as well, but can't promise will know how to help) might
> be
> > able to help.
>
> Thanks for replying.  I posted more detailed code samples on SO:
> https://urldefense.proofpoint.com/v2/url?u=https-
> 3A__stackoverflow.com_questions_44530112_how-2Dto-2Dget-2Djxpath-2Dto-
> 2Dcleanly-2Dset-2Dlist-2Dcollection-2Dentries&d=DwIFaQ&c=LFYZ-
> o9_HUMeMTSQicvjIg&r=OsTemSXEn-xy2uk0vYF_EA&m=nfT2LEhdW7RV4azBV5z7cO-
> vMKzYetKiHBtDCkt0CoI&s=AXR_qT2s9pltw3Q7IPZwifyv91V3YxSISo5Jt_B3KE4&e=  .
>
> > ________________________________
> > From: "KARR, DAVID" <[hidden email]>
> > To: Commons Users List <[hidden email]>
> > Sent: Wednesday, 14 June 2017 6:11 AM
> > Subject: [jxpath] How to add an entry to a list?
> >
> >
> >
> > If a property in a bean I'm trying to manipulate with jxpath is a
> List,
> > how do I set a value in an entry of that list?
> >
> >
> > I read the info at "Modifying Object Graphs", but it's still not clear
> > from this how I would do this.
> >
> >
> > I've figured out how to get the list created, either with an explicit
> > "setValue()", or with a "createPathAndSetValue()" along with a factory
> > and createObject() method set to look for that property, but if I try
> to
> > set a value into the list, it fails apparently because the list is
> still
> > zero size.
> >
> >
> > The only way I can hack this to work is to initialize the list
> property
> > to an ArrayList with the required number of dummy elements already
> added
> > to it, so the subscript reference works.
> >
> >
> > I'm using JXPath so that I can write tests with a little less
> > boilerplate and focus on pure business logic.  Ideally, I'd like
> JXPath
> > (or perhaps a factory) to do the "obvious stuff".
> >
> >
> >
> > ---------------------------------------------------------------------
> >
> > To unsubscribe, e-mail: [hidden email]
> >
> > For additional commands, e-mail: [hidden email]
>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
>
> Т���������������������������������������������������������������������ХF
> �V�7V'67&�&R�R���âW6W"�V�7V'67&�&T6�����2�6�R��&pФf�"FF�F����6����G2�R��
> �âW6W"ֆV�6�����2�6�R��&pР

>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]