com.alibaba.fastjson.annotation.JSONField Java Examples

The following examples show how to use com.alibaba.fastjson.annotation.JSONField. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Rap2Generator.java    From rap2-generator with Apache License 2.0 6 votes vote down vote up
/**
 * <p class="detail">
 * 功能:判断字段类型是否为时间类型,若字段写了多个注解则优先级为DateTimeFormat(spring)>JSONField(fastjson)>JsonFormat(jackson),异常就返回""
 * </p>
 *
 * @param className :类名
 * @param fieldName :字段名
 * @return boolean
 * @author Kings
 * @date 2019.11.02
 */
private String getDayPattern(String className, String fieldName) {
    try {
        Class<?> parseClass = Class.forName(className);
        DateTimeFormat dateTimeFormat = parseClass.getDeclaredField(fieldName).getAnnotation(DateTimeFormat.class);
        if (dateTimeFormat != null) {
            return dateTimeFormat.pattern();
        }
        JSONField jsonField = parseClass.getDeclaredField(fieldName).getAnnotation(JSONField.class);
        if (jsonField != null) {
            return jsonField.format();
        }
        JsonFormat jsonFormat = parseClass.getDeclaredField(fieldName).getAnnotation(JsonFormat.class);
        if (jsonFormat != null) {
            return jsonFormat.pattern();
        }
        return "";
    } catch (Exception e) {
        return "";
    }
}
 
Example #2
Source File: Rap2WebGenerator.java    From rap2-generator with Apache License 2.0 6 votes vote down vote up
/**
 * <p class="detail">
 * 功能:判断字段类型是否为时间类型,若字段写了多个注解则优先级为DateTimeFormat(spring)>JSONField(fastjson)>JsonFormat(jackson),异常就返回""
 * </p>
 *
 * @param className :类名
 * @param fieldName :字段名
 * @return boolean
 * @author Kings
 * @date 2019.11.02
 */
private String getDayPattern(String javaDirPath,String className, String fieldName) {
    try {
        Class<?> parseClass = getCompileClass(javaDirPath,className);
        DateTimeFormat dateTimeFormat = parseClass.getDeclaredField(fieldName).getAnnotation(DateTimeFormat.class);
        if (dateTimeFormat != null) {
            return dateTimeFormat.pattern();
        }
        JSONField jsonField = parseClass.getDeclaredField(fieldName).getAnnotation(JSONField.class);
        if (jsonField != null) {
            return jsonField.format();
        }
        JsonFormat jsonFormat = parseClass.getDeclaredField(fieldName).getAnnotation(JsonFormat.class);
        if (jsonFormat != null) {
            return jsonFormat.pattern();
        }
        
        return "";
    } catch (Exception e) {
        return "";
    }
}
 
Example #3
Source File: AVRelation.java    From java-unified-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a query that can be used to query the subclass objects in this relation.
 *
 * @param clazz The AVObject subclass.
 * @return A AVQuery that restricts the results to objects in this relations.
 */
@JSONField(serialize=false)
public AVQuery<T> getQuery(Class<T> clazz) {
  if (getParent() == null || StringUtil.isEmpty(getParent().getObjectId())) {
    throw new IllegalStateException("unable to encode an association with an unsaved AVObject");
  }

  Map<String, Object> map = new HashMap<String, Object>();
  map.put("object", Utils.mapFromPointerObject(AVRelation.this.getParent()));
  map.put("key", AVRelation.this.getKey());

  String targetClassName = getTargetClass();
  if (StringUtil.isEmpty(targetClassName)) {
    targetClassName = getParent().getClassName();
  }
  AVQuery<T> query = new AVQuery<T>(targetClassName, clazz);
  query.addWhereItem("$relatedTo", null, map);
  if (StringUtil.isEmpty(getTargetClass())) {
    query.getParameters().put("redirectClassNameForKey", this.getKey());
  }

  return query;
}
 
Example #4
Source File: MyFieldSerializer.java    From dpCms with Apache License 2.0 6 votes vote down vote up
public MyFieldSerializer(FieldInfo fieldInfo){
    
    this.fieldInfo = fieldInfo;
    fieldInfo.setAccessible(true);

    this.double_quoted_fieldPrefix = '"' + fieldInfo.getName() + "\":";

    this.single_quoted_fieldPrefix = '\'' + fieldInfo.getName() + "\':";

    this.un_quoted_fieldPrefix = fieldInfo.getName() + ":";

    JSONField annotation = fieldInfo.getAnnotation(JSONField.class);
    if (annotation != null) {
        for (SerializerFeature feature : annotation.serialzeFeatures()) {
            if (feature == SerializerFeature.WriteMapNullValue) {
                writeNull = true;
            }
        }
    }
}
 
Example #5
Source File: CarreraMessage.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@JSONField(serialize = false)
public Map<String, String> getRmqProperties() {
    HashMap<String, String> propertyMap = new HashMap<>();
    if (StringUtils.isNotBlank(getKey()))
        propertyMap.put(MessageConst.PROPERTY_KEYS, getKey());
    if (StringUtils.isNotBlank(getTags()))
        propertyMap.put(MessageConst.PROPERTY_TAGS, getTags());
    propertyMap.put(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX, createUniqID());

    Map<String, String> msgProperties = this.getMsgProperties();
    if (msgProperties != null) {
        propertyMap.putAll(msgProperties);
    }

    // PROPERTY_WAIT_STORE_MSG_OK 这个属性没用。
    //propertyMap.put(MessageConst.PROPERTY_WAIT_STORE_MSG_OK, Boolean.toString(true));
    return propertyMap;
}
 
Example #6
Source File: AVFile.java    From java-unified-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Get data stream in blocking mode.
 * @return data stream.
 * @throws Exception for file not found or io problem.
 */
@JSONField(serialize = false)
public InputStream getDataStream() throws Exception {
  String filePath = "";
  if(!StringUtil.isEmpty(localPath)) {
    filePath = localPath;
  } else if (!StringUtil.isEmpty(cachePath)) {
    filePath = cachePath;
  } else if (!StringUtil.isEmpty(getUrl())) {
    File cacheFile = FileCache.getIntance().getCacheFile(getUrl());
    if (null == cacheFile || !cacheFile.exists()) {
      FileDownloader downloader = new FileDownloader();
      downloader.execute(getUrl(), cacheFile);
    }
    if (null != cacheFile) {
      filePath = cacheFile.getAbsolutePath();
    }
  }
  if(!StringUtil.isEmpty(filePath)) {
    logger.d("dest file path=" + filePath);
    return FileCache.getIntance().getInputStreamFromFile(new File(filePath));
  }
  logger.w("failed to get dataStream.");
  return null;
}
 
Example #7
Source File: Annotation.java    From cicada with MIT License 5 votes vote down vote up
@JSONField(serialize = false)
public Endpoint getEndpoint() {
  Endpoint endpoint = new Endpoint();
  endpoint.setIp(ip);
  endpoint.setPort(port);
  return endpoint;
}
 
Example #8
Source File: ConsumeGroupBo.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@JSONField(serialize = false)
public Map<Long, List<Long>> getConsumeModeLongMapper() {
    if (MapUtils.isEmpty(consumeModeMapper)) {
        return null;
    }
    Map<Long, List<Long>> mapper = Maps.newHashMap();
    for (Map.Entry<String, List<Long>> entry : consumeModeMapper.entrySet()) {
        mapper.put(Long.parseLong(entry.getKey()), Lists.newArrayList(entry.getValue()));
    }
    return mapper;
}
 
Example #9
Source File: JsonUtil.java    From game-server with MIT License 5 votes vote down vote up
/**
 * 读取get set方法
 * 
 * @param cls
 * @param methods
 * @param fmmap
 * @param haveJSONField
 */
private static void register(Class<?> cls, Method[] methods, Map<String, FieldMethod> fmmap,
		boolean haveJSONField) {
	Field[] fields = cls.getDeclaredFields();
	for (Field field : fields) {
		try {
			if (Modifier.isStatic(field.getModifiers())) {
				continue;
			}
			JSONField fieldAnnotation = field.getAnnotation(JSONField.class);
			if (haveJSONField && fieldAnnotation == null) {
				continue;
			}
			String fieldGetName = parGetName(field);
			String fieldSetName = ReflectUtil.parSetName(field);
			Method fieldGetMet = getGetMet(methods, fieldGetName);
			Method fieldSetMet = ReflectUtil.getSetMet(methods, fieldSetName);
			if (fieldGetMet != null && fieldSetMet != null) {
				FieldMethod fgm = new FieldMethod(fieldGetMet, fieldSetMet, field);
				fmmap.put(fgm.getName(), fgm);
			} else {
				System.out.println("找不到set或get方法 " + cls.getName() + " field:" + field.getName());
			}
		} catch (Exception e) {
			System.out.println("register field:" + cls.getName() + ":" + field.getName() + " " + e);
			continue;
		}
	}
	Class<?> scls = cls.getSuperclass();
	if (scls != null) {
		register(scls, scls.getDeclaredMethods(), fmmap, haveJSONField);
	}
}
 
Example #10
Source File: RdbMediaSrcParameter.java    From DataLink with Apache License 2.0 5 votes vote down vote up
@JSONField(serialize = false)
public void setEncryptPassword(String password) {
    if(StringUtils.isNotBlank(password)){
        this.password = DbConfigEncryption.encrypt(password);
    }else{
        this.password = "";
    }
}
 
Example #11
Source File: LogFormats.java    From basic-tools with MIT License 5 votes vote down vote up
private static String getJSONFieldName(Field field) {
    JSONField annotation = field.getAnnotation(JSONField.class);
    if(annotation!=null){
        return annotation.name();
    }
    return UNKNOWN;
}
 
Example #12
Source File: RemotingCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@JSONField(serialize = false)
public RemotingCommandType getType() {
    if (this.isResponseType()) {
        return RemotingCommandType.RESPONSE_COMMAND;
    }

    return RemotingCommandType.REQUEST_COMMAND;
}
 
Example #13
Source File: ConsumeGroupBo.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@JSONField(serialize = false)
public Map<Long, List<Long>> getConsumeModeLongMapper() {
    if (MapUtils.isEmpty(consumeModeMapper)) {
        return null;
    }
    Map<Long, List<Long>> mapper = Maps.newHashMap();
    for (Map.Entry<String, List<Long>> entry : consumeModeMapper.entrySet()) {
        mapper.put(Long.parseLong(entry.getKey()), Lists.newArrayList(entry.getValue()));
    }
    return mapper;
}
 
Example #14
Source File: OperationMethod.java    From SoloPi with Apache License 2.0 5 votes vote down vote up
/**
 * 获取参数Key Set
 * @return
 */
@JSONField(serialize=false)
public Set<String> getParamKeys() {
    if (operationParam == null) {
        return new HashSet<>(0);
    }

    return operationParam.keySet();
}
 
Example #15
Source File: DefaultFieldDeserializer.java    From uavstack with Apache License 2.0 5 votes vote down vote up
public DefaultFieldDeserializer(ParserConfig config, Class<?> clazz, FieldInfo fieldInfo){
    super(clazz, fieldInfo);
    JSONField annotation = fieldInfo.getAnnotation();
    if (annotation != null) {
        Class<?> deserializeUsing = annotation.deserializeUsing();
        customDeserilizer = deserializeUsing != null && deserializeUsing != Void.class;
    }
}
 
Example #16
Source File: AVObject.java    From java-unified-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Get request endpoint.
 * @return endpoint.
 */
@JSONField(serialize = false)
public String getRequestRawEndpoint() {
  if (StringUtil.isEmpty(getObjectId())) {
    return "/1.1/classes/" + this.getClassName();
  } else {
    return "/1.1/classes/" + this.getClassName() + "/" + getObjectId();
  }
}
 
Example #17
Source File: RecruitEntity.java    From microservice-recruit with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
@JSONField(serialize = false, deserialize = false)
public void deserializeFields() {
    this.skillList = JSONObject.parseObject(skillStr, new TypeReference<List<SkillRule>>(){});
}
 
Example #18
Source File: Shop.java    From flash-waimai with MIT License 4 votes vote down vote up
@JSONField(name="_id")
public String get_id() {
    return _id;
}
 
Example #19
Source File: Shop.java    From flash-waimai with MIT License 4 votes vote down vote up
@JSONField(name="_id")
public void set_id(String _id) {
    this._id = _id;
}
 
Example #20
Source File: FungibleDetailData.java    From evt4j with MIT License 4 votes vote down vote up
@JSONField(ordinal = 6)
public Permission getIssue() {
    return issue;
}
 
Example #21
Source File: MenuButton.java    From wechat4j with Apache License 2.0 4 votes vote down vote up
@JSONField(name="media_id")
public String getMediaId() {
	return mediaId;
}
 
Example #22
Source File: RemotingCommand.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
/**
 * 是否是rpc-oneway
 * @return ;
 */
@JSONField(serialize = false)
public boolean isOnewayRPC() {
    int bits = 1 << RPC_ONEWAY;
    return (this.flag & bits) == bits;
}
 
Example #23
Source File: NewFungibleAction.java    From evt4j with MIT License 4 votes vote down vote up
@JSONField(name = "total_supply")
public String getTotalSupply() {
    return totalSupply.toString();
}
 
Example #24
Source File: GetGroupInfo.java    From simple-robot-core with Apache License 2.0 4 votes vote down vote up
/**
 * 获取通过此类型请求而获取到的参数的返回值的类型
 */
@Override
@JSONField(serialize = false)
default Class<? extends GroupInfo> resultType(){
    return GroupInfo.class;
}
 
Example #25
Source File: GetGroupMemberInfo.java    From simple-robot-core with Apache License 2.0 4 votes vote down vote up
/**
 * 获取通过此类型请求而获取到的参数的返回值的类型
 */
@Override
@JSONField(serialize = false)
default Class<? extends GroupMemberInfo> resultType(){
    return GroupMemberInfo.class;
}
 
Example #26
Source File: GetBanList.java    From simple-robot-core with Apache License 2.0 4 votes vote down vote up
/**
 * 获取通过此类型请求而获取到的参数的返回值的类型
 */
@Override
@JSONField(serialize = false)
default Class<? extends BanList> resultType(){
    return BanList.class;
}
 
Example #27
Source File: EveriPassAction.java    From evt4j with MIT License 4 votes vote down vote up
@Override
@JSONField(deserialize = false, serialize = false)
public String getDomain() {
    return super.getDomain();
}
 
Example #28
Source File: GetGroupTopNote.java    From simple-robot-core with Apache License 2.0 4 votes vote down vote up
/**
 * 获取通过此类型请求而获取到的参数的返回值的类型
 */
@Override
@JSONField(serialize = false)
default Class<? extends GroupTopNote> resultType(){
    return GroupTopNote.class;
}
 
Example #29
Source File: RequestContext.java    From app-engine with Apache License 2.0 4 votes vote down vote up
@JSONField(serialize = false)
public HttpServletRequest getOriginRequest() {
    return originRequest;
}
 
Example #30
Source File: WontonNetRule.java    From mcg-helper with Apache License 2.0 4 votes vote down vote up
@JSONField(name = "Device")
public String getDevice() {
	return Device;
}