hypersistence-utils: Cannot be transformed to Json object

Hi all,

I’m using hibernate-types to serialize/deserialize list of my object with MySQL as below:

public class DefaultMessage {
    # few properties here with its getter/setter
}

public class Project {
    @Type(type = "json")
    @Column(name = "default_messages", columnDefinition = "json")
    private List<DefaultMessage> defaultMessages;

    # Getter/setter
}

Of course, I have defined map supper class and @TypeDef but it always return cannot be transformed to Json object.

Exception:

2018-05-29 19:00:10,343 WARN  [http-nio-8088-exec-4] ? (:) - The given string value: [B@4ad8cfea cannot be transformed to Json object
java.lang.IllegalArgumentException: The given string value: [B@4ad8cfea cannot be transformed to Json object
	at com.vladmihalcea.hibernate.type.util.ObjectMapperWrapper.fromString(ObjectMapperWrapper.java:52) ~[hibernate-types-52-2.2.1.jar:?]
	at com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor.fromString(JsonTypeDescriptor.java:87) ~[hibernate-types-52-2.2.1.jar:?]
	at com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor.wrap(JsonTypeDescriptor.java:110) ~[hibernate-types-52-2.2.1.jar:?]
	at com.vladmihalcea.hibernate.type.json.internal.AbstractJsonSqlTypeDescriptor$1.doExtract(AbstractJsonSqlTypeDescriptor.java:34) ~[hibernate-types-52-2.2.1.jar:?]
	at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:261) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:257) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:247) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:333) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2868) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1747) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1673) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.loader.Loader.getRow(Loader.java:1562) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:732) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.loader.Loader.processResultSet(Loader.java:991) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.loader.Loader.doQuery(Loader.java:949) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.loader.Loader.doList(Loader.java:2692) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.loader.Loader.doList(Loader.java:2675) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.loader.Loader.list(Loader.java:2502) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:392) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1490) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
	at org.hibernate.query.internal.AbstractProducedQuery.getSingleResult(AbstractProducedQuery.java:1463) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'B': was expecting ('true', 'false' or 'null')

Can you give me few suggestions to solve problem?

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 21 (10 by maintainers)

Most upvoted comments

Try to give your JsonB-Class an implements Serializable - at least that worked for me

Hibernate Types does not require the Jackson Guava dependency. Your application needs it because you are using ImmutableMap.

Try to give your JsonB-Class an implements Serializable - at least that worked for me

This solved my issue ! Thanks !

@vladmihalcea I don’t think so, this is real JSON string that stored in MySQL: []

I’m using the getEntityManager().find(type, id) method for loading my record and parser the field default_messages with its data [] into List<DefaultMessage> but could not. It throws exception as issue named.

Thanks

Unrecognized token ‘B’: was expecting (‘true’, ‘false’ or ‘null’)

That’s because your JSON is malformed. You need a valid JSON. Just try to create a JsonNode from the String JSON and you’ll see it fails.