Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved JSONField(format=xxxx) support
- Loading branch information
Showing
12 changed files
with
133 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/alibaba/fastjson/parser/deserializer/ContextObjectDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.alibaba.fastjson.parser.deserializer; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
import com.alibaba.fastjson.parser.DefaultJSONParser; | ||
|
||
public abstract class ContextObjectDeserializer implements ObjectDeserializer { | ||
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) { | ||
return deserialze(parser, type, fieldName, null, 0); | ||
} | ||
|
||
public abstract <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName, String format, int features); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/alibaba/fastjson/serializer/ContextObjectSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.alibaba.fastjson.serializer; | ||
|
||
import java.io.IOException; | ||
|
||
public interface ContextObjectSerializer extends ObjectSerializer { | ||
void write(JSONSerializer serializer, // | ||
Object object, // | ||
BeanContext context) throws IOException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/java/com/alibaba/json/bvt/jdk8/LocalDateTimeTest3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.alibaba.json.bvt.jdk8; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import org.junit.Assert; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.annotation.JSONField; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class LocalDateTimeTest3 extends TestCase { | ||
|
||
public void test_for_issue() throws Exception { | ||
String text = "{\"date\":\"20111203\"}"; | ||
VO vo = JSON.parseObject(text, VO.class); | ||
|
||
Assert.assertEquals(2011, vo.date.getYear()); | ||
Assert.assertEquals(12, vo.date.getMonthValue()); | ||
Assert.assertEquals(03, vo.date.getDayOfMonth()); | ||
Assert.assertEquals(0, vo.date.getHour()); | ||
Assert.assertEquals(0, vo.date.getMinute()); | ||
Assert.assertEquals(0, vo.date.getSecond()); | ||
|
||
Assert.assertEquals(text, JSON.toJSONString(vo)); | ||
} | ||
|
||
private static class VO { | ||
@JSONField(format="yyyyMMdd") | ||
public LocalDateTime date; | ||
|
||
} | ||
} |