gpt4 book ai didi

java - 从序列化中排除类和命名空间?

转载 作者:行者123 更新时间:2023-12-01 13:42:32 28 4
gpt4 key购买 nike

我正在尝试使用 Jackson 序列化一个相当大的结构。
但是,它还尝试导出许多我永远不需要的子结构(导致 JsonMappingException:找不到类的序列化器)

那么如何从序列化中排除类和命名空间呢?

或者,如何将我的类的属性标记为排除/忽略?

最佳答案

如果您确实有权访问要排除的子结构,请使用transient关键字。

transient is a Java keyword which marks a member variable not to be serialized when it is persisted to streams of bytes. When an object is transferred through the network, the object needs to be 'serialized'. Serialization converts the object state to serial bytes. Those bytes are sent over the network and the object is recreated from those bytes. Member variables marked by the java transient keyword are not transferred, they are lost intentionally.

http://en.wikibooks.org/wiki/Java_Programming/Keywords/transient

关于java - 从序列化中排除类和命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20598607/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com