/src/main/java/com/alibaba/fastjson/parser/deserializer/LocaleDeserializer.java
Java | 36 lines | 26 code | 10 blank | 0 comment | 6 complexity | bf78be1173630096f96cace548c5204e MD5 | raw file
- package com.alibaba.fastjson.parser.deserializer;
- import java.lang.reflect.Type;
- import java.util.Locale;
- import com.alibaba.fastjson.parser.DefaultJSONParser;
- import com.alibaba.fastjson.parser.JSONToken;
- public class LocaleDeserializer implements ObjectDeserializer {
- public final static LocaleDeserializer instance = new LocaleDeserializer();
- @SuppressWarnings("unchecked")
- public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
- String text = (String) parser.parse();
-
- if (text == null) {
- return null;
- }
-
- String[] items = text.split("_");
-
- if (items.length == 1) {
- return (T) new Locale(items[0]);
- }
-
- if (items.length == 2) {
- return (T) new Locale(items[0], items[1]);
- }
-
- return (T) new Locale(items[0], items[1], items[2]);
- }
- public int getFastMatchToken() {
- return JSONToken.LITERAL_STRING;
- }
- }