scala case class extends abstract : Argument #0 of constructor ...

683 views
Skip to first unread message

Ramon Buckland

unread,
Apr 3, 2014, 5:59:15 PM4/3/14
to jackso...@googlegroups.com
Hi

I have some simple case classes 

sealed abstract class XYPersonCommand(@jsonProperty val timestamp: Long)
case class ABCRegisterNewPersonExtended(@jsonIgnore override val timestamp: Long,// = DateTime.now.getMillis,
                                        firstname: String,
                                        surname: String,
                                        emailAddress: String,
                                        campusOfRegistration: String,
                                        dob: Option[LocalDate]) extends XYPersonCommand(timestamp)

When I try to deserialise this case class, I get the following error.
I recall / throught I fixed this about 12 months ago by adding the @jsonProperty annotation to the super class properties .. but alas it is alluding me,
I have found a few issues that relate .. on error, but not to this. (if I remove the timestamp) from the c'tor, by changing abstract class to not have the field..
it all disappears:

thoughts ?

Argument #0 of constructor [constructor for com.soqqo.luap.web.marshalling.ABCRegisterNewPersonExtended, annotations: [null]] has no property name annotation; must have name when multiple-paramater constructor annotated as Creator
com.fasterxml.jackson.databind.JsonMappingException: Argument #0 of constructor [constructor for com.soqqo.luap.web.marshalling.ABCRegisterNewPersonExtended, annotations: [null]] has no property name annotation; must have name when multiple-paramater constructor annotated as Creator
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:268)


Nate Bauernfeind

unread,
Apr 3, 2014, 7:48:47 PM4/3/14
to jackso...@googlegroups.com
It's quite possible that the case class deserializer can't handle json ignore on a parameter. I do not see any tests for that use case here:

Is there any chance your @JsonIgnore is from org.codehaus instead of com.fasterxml?

Also, since the base class has timestamp as a val already, does it work if you change "override val timestamp" to "private val _timestamp" and let the accessor exist from the super class?

Nate


--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher Currie

unread,
Apr 3, 2014, 8:17:02 PM4/3/14
to jackso...@googlegroups.com
The root cause here is that, when matching properties up to constructor parameters, the BeanIntrospector uses JVM reflection to look at "declared fields", and the Scala compiler isn't generating a field for this val in the derived class. Thus, it finds "timestamp" as a member of the base class, and then starts *at the base class*, when looking for a matching constructor parameter.

I'll work on a fix that will ask the introspector to start at the most derived class when looking for constructor arguments; with luck that should fix it without breaking a bunch of other tests.

Christopher Currie

unread,
Apr 4, 2014, 2:30:50 AM4/4/14
to jackso...@googlegroups.com
I've implemented a fix for this, it's available on 2.3.3-SNAPSHOT and 2.4.0-SNAPSHOT.
Reply all
Reply to author
Forward
0 new messages