fastjson icon indicating copy to clipboard operation
fastjson copied to clipboard

fastjson doesn't parse timestamp wrapped with text format

Open nikolaslaolao opened this issue 6 years ago • 6 comments

When Fastjson parses timestamp wrapped with text format, for example, "1570636800000", it doesn't parse this timestamp because the timestamp has quote. If we use replaceAll to remove quote then become 1570636800000, Fastjson is able to parse it. This issue annoys to RequestBody Object to receive JSON from others. Can it be fixed?

nikolaslaolao avatar Oct 16 '19 19:10 nikolaslaolao

Error: FASTJSON parse error Text 1565582400000 to 0

nikolaslaolao avatar Oct 16 '19 19:10 nikolaslaolao

when it comes to LocalDateTime or LocalDate in JDK8

nikolaslaolao avatar Oct 16 '19 19:10 nikolaslaolao

@nikolaslaolao , could you provide the code that doesn't work as expected?

valyala avatar Oct 16 '19 21:10 valyala

@nikolaslaolao , could you provide the code that doesn't work as expected?

String d={createTime:"1565582400000"}; GetDate date=JSON.parseObject(d, GetDate.class);

Error: FASTJSON parse error Text 1565582400000 to 0

GetDate.class { private LocalDateTime createTime;

set... get... }

nikolaslaolao avatar Nov 04 '19 17:11 nikolaslaolao

@nikolaslaolao , could you provide the code that doesn't work as expected?

@Test public void test(){ String date1="{createTime:"1570636800000"}"; String date2="{createTime:1570636800000}"; LoginRequestDTO dto=JSON.parseObject(date1,LoginRequestDTO.class); } date1 has an error Error: FASTJSON parse error Text 1570636800000 to 0

date2 has no error

nikolaslaolao avatar Nov 04 '19 17:11 nikolaslaolao

It looks like you posted the issue in incorrect project - this fastjson is Go package, while you need fastjson for Java :)

valyala avatar Nov 04 '19 22:11 valyala