Re: [Simple-support] Constructor injection problems
Brought to you by:
niallg
|
From: Andrew S. <and...@ti...> - 2012-06-28 16:16:04
|
Hi Niall,
That's strange, since I'm using Simple 2.6.4. (By the way, it's
required=false, not required=true that I had to include.)
Thanks,
Andrew
On Thu, Jun 28, 2012 at 9:24 AM, Niall Gallagher
<gal...@ya...>wrote:
> Hi Andrew,
>
> This is only true for much older versions of Simple, for newer versions
> required=true would not be needed in the annotation.
>
> Niall
>
>
> --- On *Wed, 27/6/12, Andrew Spinner <and...@ti...>* wrote:
>
>
> From: Andrew Spinner <and...@ti...>
> Subject: Re: [Simple-support] Constructor injection problems
> To:
> Cc: sim...@li...
> Received: Wednesday, 27 June, 2012, 12:21 PM
>
>
> Hi Simon, Niall,
>
> Thanks for your suggestions. I've tracked it down to null values being
> passed to the constructor. Although my fields were annotated with
> @Element(required = false), I hadn't realised that my constructor arguments
> also had to be annotated with required=false, and this turned out to be the
> problem. Perhaps this could be made clearer in the documentation (although
> other people may not naturally make this error).
>
> Thanks for your help!
>
> Andrew
>
>
> On Wed, Jun 27, 2012 at 1:19 PM, Niall Gallagher <
> gal...@ya... <http://mc/compose?to=...@ya...>
> > wrote:
>
> Is your class an inner class, if so is it static? If it is inner and not
> static it can be be instantiated. If this is not the problem, send me a
> test case proving the problem, ill see what the problem is here.
>
> On a side note, I really doubt there is a bug here, constructor injection
> has been very heavily tested in recent releases. Make sure u are using the
> most recent release.
>
> --- On *Mon, 25/6/12, Andrew Spinner <and...@ti...<http://mc/compose?to=...@ti...>
> >* wrote:
>
>
> From: Andrew Spinner <and...@ti...<http://mc/compose?to=...@ti...>
> >
> Subject: [Simple-support] Constructor injection problems
> To: sim...@li...<http://mc/compose?to=...@li...>
> Received: Monday, 25 June, 2012, 9:27 AM
>
>
> Hello, and thanks for this lightweight framework,
>
> I'm having some problems with constructor injection for my immutable class.
>
> My instance variables are all final, and are all serialised by Simple.
> However, I don't need all the fields to be deserialised - some of the
> fields are derived, being based on mathematical calculations of the other
> fields. These derived variables are set in the constructor, based on the
> parameters passed to the constructor.
>
> It doesn't make logical sense to pass values of these derived variables
> into the constructor, because they're not needed, and will be discarded.
> However, I've got to do so, or I'll get a ConstructorException, saying "no
> constructor accepts all read only values."
>
> This isn't my production code, just an example:
>
> public class calc
> {
> @Element(name="number")
> private final int number;
> @Element(name="numberSquared")
> private final int numberSquared;
>
> //extra constructor I have to provide
> public Calc(@Element(name="number") int number,
> @Element(name="numberSquared") int numberSquared)
> {
> this(number); //ignores numberSquared parameter, letting chained
> constructor calculate value for itself
> }
>
> //usual constructor
> Calc(int number)
> {
> this.number = number;
> numberSquared = number * number; //ignoring parameter and calculating
> value for itself
> }
>
> Unfortunately, even when I create this extra constructor, I still get a
> PersistenceException: "Constructor not matched for class." As far as I can
> see, I've annotated the constructor correctly, providing a parameter for
> every possible field.
>
> Short of me providing my actual code, is there anything I could look at
> that might fix it?
>
> As a suggestion, it might be useful for PersistenceException to provided
> more specific information about how the constructor isn't matching.
>
> Thanks,
>
> Andrew
>
> -----Inline Attachment Follows-----
>
>
> ------------------------------------------------------------------------------
> 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/
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> Simple-support mailing list
> Sim...@li...<http://mc/compose?to=...@li...>
> https://lists.sourceforge.net/lists/listinfo/simple-support
>
>
>
>
> -----Inline Attachment Follows-----
>
>
> ------------------------------------------------------------------------------
> 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/
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> Simple-support mailing list
> Sim...@li...<http://mc/compose?to=...@li...>
> https://lists.sourceforge.net/lists/listinfo/simple-support
>
>
|