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
}
}
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.
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.