Fastjson: deserialize to String loses blanks

Created on 24 Jul 2019  ·  3Comments  ·  Source: alibaba/fastjson

Deserialize from bytes to String loses blanks, is that correct?
If the target Class is String.class, should it just build string from bytes?

import com.alibaba.fastjson.JSON;
import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import static java.nio.charset.StandardCharsets.UTF_8;

public class TestFastJson {

    @Test
    public void testJsonParse() throws IOException {
        String s = "{\"code\": \"200\", \"message\":  \"success\"}";  // -----> contains blanks
        ByteArrayInputStream bs = new ByteArrayInputStream(s.getBytes(UTF_8));
        String data = JSON.parseObject(bs, UTF_8, String.class);
        Assert.assertEquals(s, data);  // -----> not equal , data lose blanks
    }
}

Most helpful comment

@wongoo Yeah.I think so.Whatever type of object you convert JSON information to. Identify it as correct as long as you ensure that the core information is not lost.What's more, fastjson does skipWhitespace processing between fields for better performance.

All 3 comments

This kind of problem has nothing to do with what you're saying.

@larryRishi does that means it's just a feature of fastjson and won't be changed? If yes, this issue can be closed.

@wongoo Yeah.I think so.Whatever type of object you convert JSON information to. Identify it as correct as long as you ensure that the core information is not lost.What's more, fastjson does skipWhitespace processing between fields for better performance.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tonysmz picture tonysmz  ·  5Comments

liubailin2017 picture liubailin2017  ·  4Comments

joviqiao picture joviqiao  ·  3Comments

lilijreey picture lilijreey  ·  4Comments

sd4324530 picture sd4324530  ·  3Comments