简体   繁体   中英

How can I change class name during serialization using Jackson

'us.package.high.MyClass' is not in the trusted packages: java.util, java.lang,us.package.low.MyClass

Classes are identical. How can I change typeId (Class name) during serialization? Now it's 'us.package.high.MyClass', but I need make it just 'MyClass';

Using the @JsonTypeInfo annotation of Jackson:

package us.package.high.MyClass;

@JsonTypeInfo(include=As.WRAPPER_OBJECT, use=Id.NAME)
public class MyClass {

...

}

If you are using Jackson to handle JSON, it will help.

If you are using another library, search about that feature.

If you are using no library to handle JSON, try to implement a toString() method and in fact implements the Serializable interface:

public  class MyClass  implements Serializable { \\... }

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