本文整理了Java中com.alibaba.fastjson.JSONException.<init>()
方法的一些代码示例,展示了JSONException.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONException.<init>()
方法的具体详情如下:
包路径:com.alibaba.fastjson.JSONException
类名称:JSONException
方法名:<init>
暂无
代码示例来源:origin: alibaba/fastjson
private void readAfter() {
int state = context.state;
int newStat = -1;
switch (state) {
case StartObject:
newStat = PropertyKey;
break;
case PropertyKey:
newStat = PropertyValue;
break;
case PropertyValue:
newStat = PropertyKey;
break;
case ArrayValue:
break;
case StartArray:
newStat = ArrayValue;
break;
default:
throw new JSONException("illegal state : " + state);
}
if (newStat != -1) {
context.state = newStat;
}
}
代码示例来源:origin: alibaba/fastjson
public boolean hasNext() {
if (context == null) {
throw new JSONException("context is null");
}
final int token = parser.lexer.token();
final int state = context.state;
switch (state) {
case StartArray:
case ArrayValue:
return token != JSONToken.RBRACKET;
case StartObject:
case PropertyValue:
return token != JSONToken.RBRACE;
default:
throw new JSONException("illegal state : " + state);
}
}
代码示例来源:origin: alibaba/fastjson
private static String toString(org.w3c.dom.Node node) {
try {
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
DOMSource domSource = new DOMSource(node);
StringWriter out = new StringWriter();
transformer.transform(domSource, new StreamResult(out));
return out.toString();
} catch (TransformerException e) {
throw new JSONException("xml node to string error", e);
}
}
代码示例来源:origin: alibaba/fastjson
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
PropertyProcessable processable;
try {
processable = this.type.newInstance();
} catch (Exception e) {
throw new JSONException("craete instance error");
}
Object object =parser.parse(processable, fieldName);
return (T) object;
}
代码示例来源:origin: alibaba/fastjson
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
try {
return (T) deserialze(parser);
} catch (Exception ex) {
throw new JSONException("parseLong error, field : " + fieldName, ex);
}
}
代码示例来源:origin: alibaba/fastjson
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
try {
return (T) deserialze(parser);
} catch (Exception ex) {
throw new JSONException("parseDecimal error, field : " + fieldName, ex);
}
}
代码示例来源:origin: alibaba/fastjson
public float floatValue() {
String strVal = numberString();
float floatValue = Float.parseFloat(strVal);
if (floatValue == 0 || floatValue == Float.POSITIVE_INFINITY) {
char c0 = strVal.charAt(0);
if (c0 > '0' && c0 <= '9') {
throw new JSONException("float overflow : " + strVal);
}
}
return floatValue;
}
代码示例来源:origin: alibaba/fastjson
public byte[] bytesValue() {
if (token == JSONToken.HEX) {
throw new JSONException("TODO");
}
return IOUtils.decodeBase64(buf, np + 1, sp);
}
代码示例来源:origin: alibaba/fastjson
public Collection<String> newCollectionByType(Class<?> type){
if (type.isAssignableFrom(HashSet.class)) {
HashSet<String> list = new HashSet<String>();
return list;
} else if (type.isAssignableFrom(ArrayList.class)) {
ArrayList<String> list2 = new ArrayList<String>();
return list2;
} else {
try {
Collection<String> list = (Collection<String>) type.newInstance();
return list;
} catch (Exception e) {
throw new JSONException(e.getMessage(), e);
}
}
}
代码示例来源:origin: alibaba/fastjson
public final void scanTrue() {
if (ch != 't') {
throw new JSONException("error parse true");
}
next();
if (ch != 'r') {
throw new JSONException("error parse true");
}
next();
if (ch != 'u') {
throw new JSONException("error parse true");
}
next();
if (ch != 'e') {
throw new JSONException("error parse true");
}
next();
if (ch == ' ' || ch == ',' || ch == '}' || ch == ']' || ch == '\n' || ch == '\r' || ch == '\t' || ch == EOI
|| ch == '\f' || ch == '\b' || ch == ':' || ch == '/') {
token = JSONToken.TRUE;
} else {
throw new JSONException("scan true error");
}
}
代码示例来源:origin: alibaba/fastjson
public final void scanFalse() {
if (ch != 'f') {
throw new JSONException("error parse false");
}
next();
if (ch != 'a') {
throw new JSONException("error parse false");
}
next();
if (ch != 'l') {
throw new JSONException("error parse false");
}
next();
if (ch != 's') {
throw new JSONException("error parse false");
}
next();
if (ch != 'e') {
throw new JSONException("error parse false");
}
next();
if (ch == ' ' || ch == ',' || ch == '}' || ch == ']' || ch == '\n' || ch == '\r' || ch == '\t' || ch == EOI
|| ch == '\f' || ch == '\b' || ch == ':' || ch == '/') {
token = JSONToken.FALSE;
} else {
throw new JSONException("scan false error");
}
}
代码示例来源:origin: alibaba/fastjson
private static Method getFactoryMethod(Class<?> clazz, Method[] methods, boolean jacksonCompatible) {
Method factoryMethod = null;
for (Method method : methods) {
if (!Modifier.isStatic(method.getModifiers())) {
continue;
}
if (!clazz.isAssignableFrom(method.getReturnType())) {
continue;
}
JSONCreator annotation = method.getAnnotation(JSONCreator.class);
if (annotation != null) {
if (factoryMethod != null) {
throw new JSONException("multi-JSONCreator");
}
factoryMethod = method;
// 不应该break,否则多个静态工厂方法上存在 JSONCreator 注解时,并不会触发上述异常抛出
}
}
if (factoryMethod == null && jacksonCompatible) {
for (Method method : methods) {
if (TypeUtils.isJacksonCreator(method)) {
factoryMethod = method;
break;
}
}
}
return factoryMethod;
}
代码示例来源:origin: alibaba/fastjson
public JSONReaderScanner(Reader reader, int features){
super(features);
this.reader = reader;
buf = BUF_LOCAL.get();
if (buf != null) {
BUF_LOCAL.set(null);
}
if (buf == null) {
buf = new char[1024 * 16];
}
try {
bufLength = reader.read(buf);
} catch (IOException e) {
throw new JSONException(e.getMessage(), e);
}
bp = -1;
next();
if (ch == 65279) { // utf8 bom
next();
}
}
代码示例来源:origin: alibaba/fastjson
private void startStructure() {
final int state = context.state;
switch (state) {
case PropertyKey:
parser.accept(JSONToken.COLON);
break;
case PropertyValue:
case ArrayValue:
parser.accept(JSONToken.COMMA);
break;
case StartArray:
case StartObject:
break;
default:
throw new JSONException("illegal state : " + context.state);
}
}
代码示例来源:origin: alibaba/fastjson
public final void scanHex() {
if (ch != 'x') {
throw new JSONException("illegal state. " + ch);
}
next();
if (ch != '\'') {
throw new JSONException("illegal state. " + ch);
}
np = bp;
next();
if (ch == '\'') {
next();
token = JSONToken.HEX;
return;
}
for (int i = 0;;++i) {
char ch = next();
if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F')) {
sp++;
continue;
} else if (ch == '\'') {
sp++;
next();
break;
} else {
throw new JSONException("illegal state. " + ch);
}
}
token = JSONToken.HEX;
}
代码示例来源:origin: alibaba/fastjson
public final Number decimalValue(boolean decimal) {
char chLocal = charAt(np + sp - 1);
try {
if (chLocal == 'F') {
return Float.parseFloat(numberString());
}
if (chLocal == 'D') {
return Double.parseDouble(numberString());
}
if (decimal) {
return decimalValue();
} else {
return doubleValue();
}
} catch (NumberFormatException ex) {
throw new JSONException(ex.getMessage() + ", " + info());
}
}
代码示例来源:origin: alibaba/fastjson
private void readBefore() {
int state = context.state;
// before
switch (state) {
case PropertyKey:
parser.accept(JSONToken.COLON);
break;
case PropertyValue:
parser.accept(JSONToken.COMMA, JSONToken.IDENTIFIER);
break;
case ArrayValue:
parser.accept(JSONToken.COMMA);
break;
case StartObject:
break;
case StartArray:
break;
default:
throw new JSONException("illegal state : " + state);
}
}
代码示例来源:origin: alibaba/fastjson
public void extract(JSONPath path, DefaultJSONParser parser, Context context) {
if (context.eval) {
Object object = parser.parse();
if (deep) {
List<Object> values = new ArrayList<Object>();
path.deepGetPropertyValues(object, values);
context.object = values;
return;
}
if (object instanceof JSONObject) {
Collection<Object> values = ((JSONObject) object).values();
JSONArray array = new JSONArray(values.size());
for (Object value : values) {
array.add(value);
}
context.object = array;
return;
} else if (object instanceof JSONArray) {
context.object = object;
return;
}
}
throw new JSONException("TODO");
}
}
代码示例来源:origin: alibaba/fastjson
public final void nextTokenWithChar(char expect) {
sp = 0;
for (;;) {
if (ch == expect) {
next();
nextToken();
return;
}
if (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\f' || ch == '\b') {
next();
continue;
}
throw new JSONException("not match " + expect + " - " + ch + ", info : " + this.info());
}
}
代码示例来源:origin: alibaba/fastjson
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
JSONLexer lexer = parser.lexer;
if (lexer.token() == JSONToken.NULL) {
lexer.nextToken(JSONToken.COMMA);
return null;
}
if (lexer.token() != JSONToken.LBRACE && lexer.token() != JSONToken.COMMA) {
throw new JSONException("syntax error");
}
lexer.nextToken();
T obj;
if (type == Point.class) {
obj = (T) parsePoint(parser, fieldName);
} else if (type == Rectangle.class) {
obj = (T) parseRectangle(parser);
} else if (type == Color.class) {
obj = (T) parseColor(parser);
} else if (type == Font.class) {
obj = (T) parseFont(parser);
} else {
throw new JSONException("not support awt class : " + type);
}
ParseContext context = parser.getContext();
parser.setContext(obj, fieldName);
parser.setContext(context);
return obj;
}
内容来源于网络,如有侵权,请联系作者删除!