content: package com.alibaba.fastjson.parser.deserializer;
  
  import java.awt.Color;
  import java.lang.reflect.Type;
  import java.util.Collections;
  import java.util.Set;
  
  import com.alibaba.fastjson.JSONException;
  import com.alibaba.fastjson.parser.DefaultJSONParser;
  import com.alibaba.fastjson.parser.JSONScanner;
  import com.alibaba.fastjson.parser.JSONToken;
  
  public class ColorDeserializer implements AutowiredObjectDeserializer {
  
      public final static ColorDeserializer instance = new ColorDeserializer();
  
      @SuppressWarnings("unchecked")
      public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
          JSONScanner lexer = (JSONScanner) parser.getLexer();
  
          if (lexer.token() != JSONToken.LBRACE && lexer.token() != JSONToken.COMMA) {
              throw new JSONException("syntax error");
          }
          lexer.nextToken();
  
          int r = 0, g = 0, b = 0, alpha = 0;
          for (;;) {
              if (lexer.token() == JSONToken.RBRACE) {
                  lexer.nextToken();
                  break;
              }
  
              String key;
              if (lexer.token() == JSONToken.LITERAL_STRING) {
                  key = lexer.stringVal();
                  lexer.nextTokenWithColon(JSONToken.LITERAL_INT);
              } else {
                  throw new JSONException("syntax error");
              }
  
              int val;
              if (lexer.token() == JSONToken.LITERAL_INT) {
                  val = lexer.intValue();
                  lexer.nextToken();
              } else {
                  throw new JSONException("syntax error");
              }
  
              if (key.equalsIgnoreCase("r")) {
                  r = val;
              } else if (key.equalsIgnoreCase("g")) {
                  g = val;
              } else if (key.equalsIgnoreCase("b")) {
                  b = val;
              } else if (key.equalsIgnoreCase("alpha")) {
                  alpha = val;
              } else {
                  throw new JSONException("syntax error, " + key);
              }
  
              if (lexer.token() == JSONToken.COMMA) {
                  lexer.nextToken(JSONToken.LITERAL_STRING);
              }
          }
  
          return (T) new Color(r, g, b, alpha);
      }
  
      public int getFastMatchToken() {
          return JSONToken.LBRACE;
      }
  
      public Set<Type> getAutowiredFor() {
          return Collections.<Type> singleton(Color.class);
      }
  
  }
  