Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

两边枚举类不相同,反序列化时报错的问题 #1498

Closed
zackhu135 opened this issue Sep 27, 2017 · 1 comment
Closed

两边枚举类不相同,反序列化时报错的问题 #1498

zackhu135 opened this issue Sep 27, 2017 · 1 comment
Milestone

Comments

@zackhu135
Copy link

zackhu135 commented Sep 27, 2017

序列化方定义的枚举类型为:

public enum BuFlag
{
  IS_NEED_CHECK_IDENTITY(1L, "a"),  HAS_CHECK_IDENTITY(2L, "b"),
  QUALITY_GRADUATE(3L, "c");
  
  private long bit;
  private String desc;
  
  private BuFlag(long bit, String desc)
  {
    this.bit = bit;
    this.desc = desc;
  }
  
  public long getBit()
  {
    return this.bit;
  }
}

反序列化定义的枚举类型为:

public enum BuFlag
{
  IS_NEED_CHECK_IDENTITY(1L, "a"),  HAS_CHECK_IDENTITY(2L, "b");
  
  private long bit;
  private String desc;
  
  private BuFlag(long bit, String desc)
  {
    this.bit = bit;
    this.desc = desc;
  }
  
  public long getBit()
  {
    return this.bit;
  }
}

反序列方定义的类没有定义QUALITY_GRADUATE(3L, "c")。
使用场景为序列方返回Set set,set里面的元素为IS_NEED_CHECK_IDENTITY,QUALITY_GRADUATE。在反序列方解析时报
Caused by: java.lang.IllegalArgumentException: No enum constant test.BuFlag.QUALITY_GRADUATE
at java.lang.Enum.valueOf(Enum.java:236)
at com.alibaba.fastjson.parser.deserializer.EnumDeserializer.deserialze(EnumDeserializer.java:61)

fastjson版本为1.2.5,试了最新版也是一样报错,请问这个有办法解决吗?可以让反序列化方在反序列时,如果没有定义QUALITY_GRADUATE,就丢弃QUALITY_GRADUATE这个值吗?

@wenshao wenshao added this to the 1.2.39 milestone Sep 27, 2017
wenshao added a commit that referenced this issue Sep 28, 2017
@wenshao
Copy link
Member

wenshao commented Oct 1, 2017

https://github.com/alibaba/fastjson/releases/tag/1.2.39
新版本我测试是好的,请验证,如果还有问题,再提新issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants