com.alibaba.fastjson.parser.deserializer.JSONPDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastjson-to-easyjson Show documentation
Show all versions of fastjson-to-easyjson Show documentation
Adapter alibaba fastjson to other json libraries. the fastjson version: 1.2.58
package com.alibaba.fastjson.parser.deserializer;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONPObject;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONLexerBase;
import com.alibaba.fastjson.parser.JSONToken;
import com.alibaba.fastjson.parser.SymbolTable;
import java.lang.reflect.Type;
/**
* Created by wenshao on 21/02/2017.
*/
public class JSONPDeserializer implements ObjectDeserializer {
public static final JSONPDeserializer instance = new JSONPDeserializer();
public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONLexerBase lexer = (JSONLexerBase) parser.getLexer();
SymbolTable symbolTable = parser.getSymbolTable();
String funcName = lexer.scanSymbolUnQuoted(symbolTable);
lexer.nextToken();
int tok = lexer.token();
if (tok == JSONToken.DOT) {
String name = lexer.scanSymbolUnQuoted(parser.getSymbolTable());
funcName += ".";
funcName += name;
lexer.nextToken();
tok = lexer.token();
}
JSONPObject jsonp = new JSONPObject(funcName);
if (tok != JSONToken.LPAREN) {
throw new JSONException("illegal jsonp : " + lexer.info());
}
lexer.nextToken();
for (; ; ) {
Object arg = parser.parse();
jsonp.addParameter(arg);
tok = lexer.token();
if (tok == JSONToken.COMMA) {
lexer.nextToken();
} else if (tok == JSONToken.RPAREN) {
lexer.nextToken();
break;
} else {
throw new JSONException("illegal jsonp : " + lexer.info());
}
}
tok = lexer.token();
if (tok == JSONToken.SEMI) {
lexer.nextToken();
}
return (T) jsonp;
}
public int getFastMatchToken() {
return 0;
}
}