Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] fasjson bug #3100

Open
smalltalkhyb opened this issue Oct 14, 2024 · 1 comment
Open

[BUG] fasjson bug #3100

smalltalkhyb opened this issue Oct 14, 2024 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@smalltalkhyb
Copy link

smalltalkhyb commented Oct 14, 2024

问题描述

反序列化出现问题

环境信息

请填写以下信息:

  • OS信息: mac m1
  • JDK信息: [e.g.:Openjdk 17]
  • 版本信息:[e.g.:Fastjson2 2.0.42]

重现步骤

如何操作可以重现该问题:

  1. 使用 xxx.xxx 方法
  2. 输入 ... 数据
  3. 出现 ... 错误
//可在此输入示例代码



### OpenIdQueryRequest
`import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
import java.io.Serializable;
import java.util.Objects;
import lombok.Generated;

@Schema(
    name = "openIdQueryRequest",
    description = "用户查询-入参"
)
@JsonTypeName("openIdQueryRequest")
public class OpenIdQueryRequest implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer identityType;
    private String openId;
    private Integer bussCode;

    public OpenIdQueryRequest identityType(Integer identityType) {
        this.identityType = identityType;
        return this;
    }

    @Schema(
        name = "identityType",
        description = "",
        requiredMode = RequiredMode.NOT_REQUIRED
    )
    @JsonProperty("identityType")
    public Integer getIdentityType() {
        return this.identityType;
    }

    public void setIdentityType(Integer identityType) {
        this.identityType = identityType;
    }

    public OpenIdQueryRequest openId(String openId) {
        this.openId = openId;
        return this;
    }

    @Schema(
        name = "openId",
        description = "三方openId (必填)",
        requiredMode = RequiredMode.NOT_REQUIRED
    )
    @JsonProperty("openId")
    public String getOpenId() {
        return this.openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public OpenIdQueryRequest bussCode(Integer bussCode) {
        this.bussCode = bussCode;
        return this;
    }

    @Schema(
        name = "bussCode",
        description = "",
        requiredMode = RequiredMode.NOT_REQUIRED
    )
    @JsonProperty("bussCode")
    public Integer getBussCode() {
        return this.bussCode;
    }

    public void setBussCode(Integer bussCode) {
        this.bussCode = bussCode;
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (o != null && this.getClass() == o.getClass()) {
            OpenIdQueryRequest openIdQueryRequest = (OpenIdQueryRequest)o;
            return Objects.equals(this.identityType, openIdQueryRequest.identityType) && Objects.equals(this.openId, openIdQueryRequest.openId) && Objects.equals(this.bussCode, openIdQueryRequest.bussCode);
        } else {
            return false;
        }
    }

    public int hashCode() {
        return Objects.hash(new Object[]{this.identityType, this.openId, this.bussCode});
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class OpenIdQueryRequest {\n");
        sb.append("    identityType: ").append(this.toIndentedString(this.identityType)).append("\n");
        sb.append("    openId: ").append(this.toIndentedString(this.openId)).append("\n");
        sb.append("    bussCode: ").append(this.toIndentedString(this.bussCode)).append("\n");
        sb.append("}");
        return sb.toString();
    }

    private String toIndentedString(Object o) {
        return o == null ? "null" : o.toString().replace("\n", "\n    ");
    }

    @Generated
    public static OpenIdQueryRequestBuilder builder() {
        return new OpenIdQueryRequestBuilder();
    }

    @Generated
    public OpenIdQueryRequest(Integer identityType, String openId, Integer bussCode) {
        this.identityType = identityType;
        this.openId = openId;
        this.bussCode = bussCode;
    }

    @Generated
    public OpenIdQueryRequest() {
    }

    @Generated
    public static class OpenIdQueryRequestBuilder {
        @Generated
        private Integer identityType;
        @Generated
        private String openId;
        @Generated
        private Integer bussCode;

        @Generated
        OpenIdQueryRequestBuilder() {
        }

        @Generated
        public OpenIdQueryRequestBuilder identityType(Integer identityType) {
            this.identityType = identityType;
            return this;
        }

        @Generated
        public OpenIdQueryRequestBuilder openId(String openId) {
            this.openId = openId;
            return this;
        }

        @Generated
        public OpenIdQueryRequestBuilder bussCode(Integer bussCode) {
            this.bussCode = bussCode;
            return this;
        }

        @Generated
        public OpenIdQueryRequest build() {
            return new OpenIdQueryRequest(this.identityType, this.openId, this.bussCode);
        }

        @Generated
        public String toString() {
            return "OpenIdQueryRequest.OpenIdQueryRequestBuilder(identityType=" + this.identityType + ", openId=" + this.openId + ", bussCode=" + this.bussCode + ")";
        }
    }
}`


### Test

`public class TestMain {


    public static void main(String[] args) {


        OpenIdQueryRequest openIdQueryRequest=new OpenIdQueryRequest();


        JSONB.parseObject(
                JSONB.toBytes(
                        openIdQueryRequest,
                        JSONWriter.Feature.WriteClassName,
                        JSONWriter.Feature.FieldBased,
                        JSONWriter.Feature.ErrorOnNoneSerializable,
                        JSONWriter.Feature.ReferenceDetection,
                        JSONWriter.Feature.WriteNulls,
                        JSONWriter.Feature.NotWriteDefaultValue,
                        JSONWriter.Feature.NotWriteHashMapArrayListClassName,
                        JSONWriter.Feature.WriteNameAsSymbol),
                OpenIdQueryRequest.class,
                new ContextAutoTypeBeforeHandler(true),
                JSONReader.Feature.UseDefaultConstructorAsPossible,
                JSONReader.Feature.ErrorOnNoneSerializable,
                JSONReader.Feature.IgnoreAutoTypeNotMatch,
                JSONReader.Feature.UseNativeObject,
                JSONReader.Feature.FieldBased);

    }
}`

### Error  

Exception in thread "main" java.lang.NullPointerException
	at java.base/java.lang.Class.isAssignableFrom(Native Method)
	at com.alibaba.fastjson2.reader.ObjectReaderBean.checkAutoType0(ObjectReaderBean.java:182)
	at com.alibaba.fastjson2.reader.ObjectReaderBean.checkAutoType(ObjectReaderBean.java:165)
	at com.alibaba.fastjson2.reader.ORG_1_3_OpenIdQueryRequest.readJSONBObject(Unknown Source)
	at com.alibaba.fastjson2.JSONB.parseObject(JSONB.java:540)
	at cn.itbox.user.api.service.TestMain.main(TestMain.java:27)

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。

相关日志输出

请复制并粘贴任何相关的日志输出。

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@smalltalkhyb smalltalkhyb added the bug Something isn't working label Oct 14, 2024
@wenshao wenshao added this to the 2.0.54 milestone Oct 27, 2024
@wenshao
Copy link
Member

wenshao commented Oct 27, 2024

问题没重现,你升级到2.0.53版本试下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants