Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json deserialization of class with no default constructor and referenced field in the provided constructor #7

Closed
larjohn opened this issue Jul 17, 2015 · 2 comments
Labels

Comments

@larjohn
Copy link

larjohn commented Jul 17, 2015

Hi,

I am using mysema QueryDSL for persistence-ORM functionality. I would like to store built query objects together in JSON format, so that I can load and reuse them. As most of the classes in QueryDSL are abstract, and I would not modify them, I have used mixins to configure their JSON serialization/deserialization:

My issue is with the PathMetadata mixin. The original PathMetadata class can be seen here:

https://github.com/querydsl/querydsl/blob/master/querydsl-core/src/main/java/com/querydsl/core/types/PathMetadata.java

The mixin that I have created for this class is the following:

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mysema.query.types.Path;
import com.mysema.query.types.PathType;

import javax.annotation.Nullable;

public abstract class PathMetadataMixin {

@JsonProperty
private Path<?>parent;

@JsonIgnore
private Path<?>root;


@JsonCreator
public PathMetadataMixin(@JsonProperty("parent")  @Nullable Path<?> parent, @JsonProperty("element") Object element, @JsonProperty("type") PathType type ) {

}

}

When I serialize an instance of this PathMetadata class, everything works as expected and it is outputted either as a whole, or with the ref attribute if it is already there. But when I try to deserialize the object, it throws a crypric exception:

Caused by: java.lang.ArrayStoreException: com.fasterxml.jackson.databind.deser.impl.ObjectIdReferenceProperty

I have found that this exception is fired here:

/com/fasterxml/jackson/core/jackson-databind/2.6.0-rc1/jackson-databind-2.6.0-rc1-sources.jar!/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java:485

Actually, in this line

creatorProps[i] = prop;

creatorProps is an array of CreatorProperty objects (although it is declared more generally) and prop is an ObjectIdReferenceProperty. Thus it cannot be added to the array.

How can I solve this?

@stickfigure
Copy link
Member

This goes beyond my Jackson knowledge, but it also doesn't seem to be JSOG-related. Perhaps you wish to ask this question on the jackson mailing list?

@larjohn
Copy link
Author

larjohn commented Jul 23, 2015

This issue was moved to FasterXML/jackson-databind#874

@larjohn larjohn closed this as completed Jul 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants