简体   繁体   中英

Java JPA with Hibernate Mapping for Class

Say I have

class Properties {
    private final MediaType mediaType; // javax.ws.rs.core;

    public MediaType getMediaType() { return mediaType; }
}

When this is saved into the SQL, it gets saved as

"type": "application",
"subtype": "x-www-form-urlencoded",
"parameters": {
    "charset": "utf-8"
},
"wildcardType": false,
"wildcardSubtype": false

How can I make this return toString version of the MediaType?

You haven't posted your entity code (or you're using Hibernate with xmls) but you do need to create a converter in which you implement conversion methods for both directions:

  1. Convert entity to database representation (that is, convert MediaType to its toString
  2. Convert database representation (string) to the entiry. This direction will be harder for you as you'll need a json mapper for that.

Here's an example of how to implement converters

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM