@SuppressWarnings("unchecked") public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) { String url = (String) parser.parse(); if (url == null) { return null; } try { return (T) new URL(url); } catch (MalformedURLException e) { throw new JSONException("create url error", e); } }
public static final Object parse(String text, int features) { if (text == null) { return null; } DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance(), features); Object value = parser.parse(); parser.handleResovleTask(value); parser.close(); return value; }
public static final Object parse( byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) { charsetDecoder.reset(); int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte()); char[] chars = ThreadLocalCache.getChars(scaleLength); ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len); CharBuffer charBuf = CharBuffer.wrap(chars); IOUtils.decode(charsetDecoder, byteBuf, charBuf); int position = charBuf.position(); DefaultJSONParser parser = new DefaultJSONParser(chars, position, ParserConfig.getGlobalInstance(), features); Object value = parser.parse(); parser.handleResovleTask(value); parser.close(); return value; }
@SuppressWarnings("unchecked") public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) { final JSONLexer lexer = parser.getLexer(); Boolean boolObj; if (lexer.token() == JSONToken.TRUE) { lexer.nextToken(JSONToken.COMMA); boolObj = Boolean.TRUE; } else if (lexer.token() == JSONToken.FALSE) { lexer.nextToken(JSONToken.COMMA); boolObj = Boolean.FALSE; } else if (lexer.token() == JSONToken.LITERAL_INT) { int intValue = lexer.intValue(); lexer.nextToken(JSONToken.COMMA); if (intValue == 1) { boolObj = Boolean.TRUE; } else { boolObj = Boolean.FALSE; } } else { Object value = parser.parse(); if (value == null) { return null; } boolObj = TypeUtils.castToBoolean(value); } if (clazz == AtomicBoolean.class) { return (T) new AtomicBoolean(boolObj.booleanValue()); } return (T) boolObj; }