Java 8 Exception: com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer has no default (no arg) constructor
up vote
0
down vote
favorite
I have a model class that has a field:
@JsonDeserialize(using = InstantDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
private OffsetDateTime offsetDt;
When a request of this model is sent to the server, my controller throws an exception:
Caused by: java.lang.IllegalArgumentException:
Class com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer
has no default (no arg) constructor
The pom.xml has the dependency of version 2.8.11:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
I understand that it is caused by @JsonDeserialize requiring no-arg constructor, but is there a workaround? Many thanks.
java json jackson fasterxml jsr310
|
show 5 more comments
up vote
0
down vote
favorite
I have a model class that has a field:
@JsonDeserialize(using = InstantDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
private OffsetDateTime offsetDt;
When a request of this model is sent to the server, my controller throws an exception:
Caused by: java.lang.IllegalArgumentException:
Class com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer
has no default (no arg) constructor
The pom.xml has the dependency of version 2.8.11:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
I understand that it is caused by @JsonDeserialize requiring no-arg constructor, but is there a workaround? Many thanks.
java json jackson fasterxml jsr310
InstantDeserializer.class
is custom deserializer class?, if i believe in that class you may declared some arg constructor without no-arg constructor
– Deadpool
Nov 9 at 20:08
@Deadpool no, it is not a custom class.. com.fasterxml.jackson.datatype.jsr310.deser
– jlp
Nov 9 at 20:10
what does your POM look like?
– Darren Forsythe
Nov 9 at 20:15
1
Look at this answer stackoverflow.com/a/45215515/4727666, you need a class with a constructor that takes no arguments, so you can extend InstantDeserializer to create your own.
– Julio Daniel Reyes
Nov 9 at 21:31
1
For the arguments, take a look at this github.com/FasterXML/jackson-datatype-jsr310/blob/master/src/…
– Julio Daniel Reyes
Nov 9 at 21:35
|
show 5 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a model class that has a field:
@JsonDeserialize(using = InstantDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
private OffsetDateTime offsetDt;
When a request of this model is sent to the server, my controller throws an exception:
Caused by: java.lang.IllegalArgumentException:
Class com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer
has no default (no arg) constructor
The pom.xml has the dependency of version 2.8.11:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
I understand that it is caused by @JsonDeserialize requiring no-arg constructor, but is there a workaround? Many thanks.
java json jackson fasterxml jsr310
I have a model class that has a field:
@JsonDeserialize(using = InstantDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
private OffsetDateTime offsetDt;
When a request of this model is sent to the server, my controller throws an exception:
Caused by: java.lang.IllegalArgumentException:
Class com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer
has no default (no arg) constructor
The pom.xml has the dependency of version 2.8.11:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
I understand that it is caused by @JsonDeserialize requiring no-arg constructor, but is there a workaround? Many thanks.
java json jackson fasterxml jsr310
java json jackson fasterxml jsr310
edited Nov 9 at 20:50
asked Nov 9 at 20:03
jlp
4091822
4091822
InstantDeserializer.class
is custom deserializer class?, if i believe in that class you may declared some arg constructor without no-arg constructor
– Deadpool
Nov 9 at 20:08
@Deadpool no, it is not a custom class.. com.fasterxml.jackson.datatype.jsr310.deser
– jlp
Nov 9 at 20:10
what does your POM look like?
– Darren Forsythe
Nov 9 at 20:15
1
Look at this answer stackoverflow.com/a/45215515/4727666, you need a class with a constructor that takes no arguments, so you can extend InstantDeserializer to create your own.
– Julio Daniel Reyes
Nov 9 at 21:31
1
For the arguments, take a look at this github.com/FasterXML/jackson-datatype-jsr310/blob/master/src/…
– Julio Daniel Reyes
Nov 9 at 21:35
|
show 5 more comments
InstantDeserializer.class
is custom deserializer class?, if i believe in that class you may declared some arg constructor without no-arg constructor
– Deadpool
Nov 9 at 20:08
@Deadpool no, it is not a custom class.. com.fasterxml.jackson.datatype.jsr310.deser
– jlp
Nov 9 at 20:10
what does your POM look like?
– Darren Forsythe
Nov 9 at 20:15
1
Look at this answer stackoverflow.com/a/45215515/4727666, you need a class with a constructor that takes no arguments, so you can extend InstantDeserializer to create your own.
– Julio Daniel Reyes
Nov 9 at 21:31
1
For the arguments, take a look at this github.com/FasterXML/jackson-datatype-jsr310/blob/master/src/…
– Julio Daniel Reyes
Nov 9 at 21:35
InstantDeserializer.class
is custom deserializer class?, if i believe in that class you may declared some arg constructor without no-arg constructor– Deadpool
Nov 9 at 20:08
InstantDeserializer.class
is custom deserializer class?, if i believe in that class you may declared some arg constructor without no-arg constructor– Deadpool
Nov 9 at 20:08
@Deadpool no, it is not a custom class.. com.fasterxml.jackson.datatype.jsr310.deser
– jlp
Nov 9 at 20:10
@Deadpool no, it is not a custom class.. com.fasterxml.jackson.datatype.jsr310.deser
– jlp
Nov 9 at 20:10
what does your POM look like?
– Darren Forsythe
Nov 9 at 20:15
what does your POM look like?
– Darren Forsythe
Nov 9 at 20:15
1
1
Look at this answer stackoverflow.com/a/45215515/4727666, you need a class with a constructor that takes no arguments, so you can extend InstantDeserializer to create your own.
– Julio Daniel Reyes
Nov 9 at 21:31
Look at this answer stackoverflow.com/a/45215515/4727666, you need a class with a constructor that takes no arguments, so you can extend InstantDeserializer to create your own.
– Julio Daniel Reyes
Nov 9 at 21:31
1
1
For the arguments, take a look at this github.com/FasterXML/jackson-datatype-jsr310/blob/master/src/…
– Julio Daniel Reyes
Nov 9 at 21:35
For the arguments, take a look at this github.com/FasterXML/jackson-datatype-jsr310/blob/master/src/…
– Julio Daniel Reyes
Nov 9 at 21:35
|
show 5 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The error says that you need a class with no arg constructor, so you could extend from InstantDeserializer
. (Take as example the code in InstantDeserializer
for the arguments of super()
)
public class DefaultInstantDeserializer extends InstantDeserializer<OffsetDateTime>
public DefaultInstantDeserializer()
super(OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
OffsetDateTime::from,
a -> OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId),
a -> OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId),
(d, z) -> d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())),
true);
Then you can use it:
@JsonDeserialize(using = DefaultInstantDeserializer.class)
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The error says that you need a class with no arg constructor, so you could extend from InstantDeserializer
. (Take as example the code in InstantDeserializer
for the arguments of super()
)
public class DefaultInstantDeserializer extends InstantDeserializer<OffsetDateTime>
public DefaultInstantDeserializer()
super(OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
OffsetDateTime::from,
a -> OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId),
a -> OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId),
(d, z) -> d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())),
true);
Then you can use it:
@JsonDeserialize(using = DefaultInstantDeserializer.class)
add a comment |
up vote
1
down vote
accepted
The error says that you need a class with no arg constructor, so you could extend from InstantDeserializer
. (Take as example the code in InstantDeserializer
for the arguments of super()
)
public class DefaultInstantDeserializer extends InstantDeserializer<OffsetDateTime>
public DefaultInstantDeserializer()
super(OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
OffsetDateTime::from,
a -> OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId),
a -> OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId),
(d, z) -> d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())),
true);
Then you can use it:
@JsonDeserialize(using = DefaultInstantDeserializer.class)
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The error says that you need a class with no arg constructor, so you could extend from InstantDeserializer
. (Take as example the code in InstantDeserializer
for the arguments of super()
)
public class DefaultInstantDeserializer extends InstantDeserializer<OffsetDateTime>
public DefaultInstantDeserializer()
super(OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
OffsetDateTime::from,
a -> OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId),
a -> OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId),
(d, z) -> d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())),
true);
Then you can use it:
@JsonDeserialize(using = DefaultInstantDeserializer.class)
The error says that you need a class with no arg constructor, so you could extend from InstantDeserializer
. (Take as example the code in InstantDeserializer
for the arguments of super()
)
public class DefaultInstantDeserializer extends InstantDeserializer<OffsetDateTime>
public DefaultInstantDeserializer()
super(OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME,
OffsetDateTime::from,
a -> OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId),
a -> OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId),
(d, z) -> d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())),
true);
Then you can use it:
@JsonDeserialize(using = DefaultInstantDeserializer.class)
answered Nov 12 at 4:30
Julio Daniel Reyes
1,977815
1,977815
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232600%2fjava-8-exception-com-fasterxml-jackson-datatype-jsr310-deser-instantdeserialize%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
InstantDeserializer.class
is custom deserializer class?, if i believe in that class you may declared some arg constructor without no-arg constructor– Deadpool
Nov 9 at 20:08
@Deadpool no, it is not a custom class.. com.fasterxml.jackson.datatype.jsr310.deser
– jlp
Nov 9 at 20:10
what does your POM look like?
– Darren Forsythe
Nov 9 at 20:15
1
Look at this answer stackoverflow.com/a/45215515/4727666, you need a class with a constructor that takes no arguments, so you can extend InstantDeserializer to create your own.
– Julio Daniel Reyes
Nov 9 at 21:31
1
For the arguments, take a look at this github.com/FasterXML/jackson-datatype-jsr310/blob/master/src/…
– Julio Daniel Reyes
Nov 9 at 21:35