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

need WriteClassName with autoboxing Long value not ending prefix 'L' #243

Closed
@zhoufenglokki

Description

@zhoufenglokki

sometime, long(design-time) maybe autoboxing to Long(run-time)

problem in code:

@Test
public void testSerialize() {
    RpcResponse response = new RpcResponse(2, new Object());
    //String json = JSON.toJSONString(response, SerializerFeature.WriteClassName); // codeA with WriteClassName, requestId is not ending with 'L'
    String json = response.toCommandJson(); //  codeA with WriteClassName, requestId is ending with 'L', and trouble other json framework
    System.out.println(json);
}


package com.test.testjson.example.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

public class RpcResponse {
    private int msgType = 50;
    private long requestId = 0;
    private JSONObject details = new JSONObject();
    private Object[] yieldResult = new Object[1];

    public RpcResponse() {

    }

    public RpcResponse(long requestId, Object result) {
        this.requestId = requestId;
        yieldResult[0] = result;
    }

    public int getMsgType() {
        return msgType;
    }

    public void setMsgType(int msgType) {
        this.msgType = msgType;
    }

    public long getRequestId() {
        return requestId;
    }

    public void setRequestId(long requestId) {
        this.requestId = requestId;
    }

    public JSONObject getDetails() {
        return details;
    }

    public void setDetails(JSONObject details) {
        this.details = details;
    }

    public Object[] getYieldResult() {
        return yieldResult;
    }

    public void setYieldResult(String[] yieldResult) {
        this.yieldResult = yieldResult;
    }

    protected Object[] fieldToArray() {
        return new Object[] { msgType, requestId, details, yieldResult };
    }

    public String toCommandJson() {
        return JSON.toJSONString(fieldToArray(), SerializerFeature.WriteClassName);
    }
}

Activity

yakolee

yakolee commented on Nov 20, 2014

@yakolee
Contributor

protected Object[] fieldToArray() {
return new Object[] { msgType, requestId, details, yieldResult };
}
object数组中requestId就是Long类型的啊

wenshao

wenshao commented on Apr 12, 2016

@wenshao
Member

很遗憾告诉你,这是一个设计问题,无法修复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @wenshao@yakolee@zhoufenglokki

        Issue actions

          need WriteClassName with autoboxing Long value not ending prefix 'L' · Issue #243 · alibaba/fastjson