[英]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 'us.package.high.MyClass' 不在受信任的包中:java.util、java.lang、us.package.low.MyClass
Classes are identical.类是相同的。 How can I change typeId (Class name) during serialization?如何在序列化期间更改 typeId(类名)? Now it's 'us.package.high.MyClass', but I need make it just 'MyClass';现在是“us.package.high.MyClass”,但我需要将其设为“MyClass”;
Using the @JsonTypeInfo
annotation of Jackson:使用Jackson的@JsonTypeInfo
注解:
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.如果您使用 Jackson 来处理 JSON,它会有所帮助。
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:如果您没有使用任何库来处理 JSON,请尝试实现一个toString()
方法,实际上实现了Serializable
接口:
public class MyClass implements Serializable { \\... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.