类com.alibaba.fastjson.PropertyNamingStrategy源码实例Demo

下面列出了怎么用com.alibaba.fastjson.PropertyNamingStrategy的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: yue-library   文件: AbstractRepository.java
/**
 * 插入数据-实体
 * 
 * @param paramIPO 参数IPO(POJO-IPO对象)
 * @param databaseFieldNamingStrategyEnum 数据库字段命名策略
 * @return 返回主键值
 */
public Long insert(Object paramIPO, FieldNamingStrategyEnum databaseFieldNamingStrategyEnum) {
	PropertyNamingStrategy propertyNamingStrategy = databaseFieldNamingStrategyEnum.getPropertyNamingStrategy();
	SerializeConfig serializeConfig = new SerializeConfig();
	serializeConfig.setPropertyNamingStrategy(propertyNamingStrategy);
	JSONObject paramJson = (JSONObject) JSONObject.toJSON(paramIPO, serializeConfig);
	return insert(paramJson);
}
 
源代码2 项目: yue-library   文件: TestController.java
/**
 * 
 * @param paramJson
 * @return
 */
@GetMapping("/get")
public Result<?> get(@RequestParam JSONObject paramJson) {
	JSONObject a = MapUtils.toPropertyNamingStrategy(paramJson, PropertyNamingStrategy.SnakeCase);
	System.out.println(a);
	return ResultInfo.success(a);
}
 
源代码3 项目: yue-library   文件: TestController.java
/**
 * 
 * @param paramJson
 * @return
 */
@GetMapping("/get")
public Result<?> get(@RequestParam JSONObject paramJson) {
	JSONObject a = MapUtils.toPropertyNamingStrategy(paramJson, PropertyNamingStrategy.SnakeCase);
	System.out.println(a);
	return ResultInfo.success(a);
}
 
源代码4 项目: uavstack   文件: TypeUtils.java
public static List<FieldInfo> computeGettersWithFieldBase(
        Class<?> clazz, //
        Map<String,String> aliasMap, //
        boolean sorted, //
        PropertyNamingStrategy propertyNamingStrategy){
    Map<String,FieldInfo> fieldInfoMap = new LinkedHashMap<String,FieldInfo>();
    for(Class<?> currentClass = clazz; currentClass != null; currentClass = currentClass.getSuperclass()){
        Field[] fields = currentClass.getDeclaredFields();
        computeFields(currentClass, aliasMap, propertyNamingStrategy, fieldInfoMap, fields);
    }
    return getFieldInfos(clazz, sorted, fieldInfoMap);
}
 
源代码5 项目: uavstack   文件: JavaBeanInfo.java
public static JavaBeanInfo build(Class<?> clazz //
        , Type type //
        , PropertyNamingStrategy propertyNamingStrategy //
        , boolean fieldBased //
        , boolean compatibleWithJavaBean
) {
    return build(clazz, type, propertyNamingStrategy, fieldBased, compatibleWithJavaBean, false);
}
 
源代码6 项目: pragmatic-java-engineer   文件: FastJsonExample.java
public static void main(String[] args) {
    User user = new User();
    user.setName("testUser");
    user.setGender("M");
    user.setNickName("nickTest");

    SerializeConfig config = new SerializeConfig();
    config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
    String str = JSON.toJSONString(user, config);
    System.out.println(str);

    user = JSON.parseObject(str, User.class);

    JSONObject jo = JSON.parseObject("{\"name\":\"test\"}");
    String name = jo.getString("name");
    String nick = jo.getString("nickName");

    System.out.println(nick);

    JSONObject jsonObject = new JSONObject();
    jsonObject.put("name", "test");

    String jsonStr = "{\"name\":\"testName\",\"interests\":[\"music\",\"basketball\"]," +
            "\"notes\":[{\"title\":\"note1\",\"contentLength\":200},{\"title\":\"note2\",\"contentLength\":100}]}";
    JSONObject jsonObject1 = JSON.parseObject(jsonStr);
    System.out.println(JSONPath.eval(jsonObject1, "$.interests.size()"));
    System.out.println(JSONPath.eval(jsonObject1, "$.interests[0]"));
    System.out.println(JSONPath.eval(jsonObject1, "$.notes[contentLength > 100].title"));
    System.out.println(JSONPath.eval(jsonObject1, "$.notes['title']"));
}
 
源代码7 项目: actframework   文件: JsonUtilConfig.java
private SerializeConfig initConfig(ActContext context) {
    SerializeConfig config = SerializeConfig.getGlobalInstance();
    PropertyNamingStrategy propertyNamingStrategy = context.fastjsonPropertyNamingStrategy();
    if (null == propertyNamingStrategy) {
        return config;
    }
    config = new SerializeConfig();
    config.propertyNamingStrategy = propertyNamingStrategy;
    return config;
}
 
源代码8 项目: uavstack   文件: TypeUtils.java
public static SerializeBeanInfo buildBeanInfo(Class<?> beanType //
        , Map<String,String> aliasMap //
        , PropertyNamingStrategy propertyNamingStrategy){
    return buildBeanInfo(beanType, aliasMap, propertyNamingStrategy, false);
}
 
源代码9 项目: uavstack   文件: TypeUtils.java
public static List<FieldInfo> computeGetters(Class<?> clazz, Map<String,String> aliasMap, boolean sorted){
    JSONType jsonType = TypeUtils.getAnnotation(clazz,JSONType.class);
    Map<String,Field> fieldCacheMap = new HashMap<String,Field>();
    ParserConfig.parserAllFieldToCache(clazz, fieldCacheMap);
    return computeGetters(clazz, jsonType, aliasMap, fieldCacheMap, sorted, PropertyNamingStrategy.CamelCase);
}
 
源代码10 项目: uavstack   文件: TypeUtils.java
private static void computeFields(
        Class<?> clazz, //
        Map<String,String> aliasMap, //
        PropertyNamingStrategy propertyNamingStrategy, //
        Map<String,FieldInfo> fieldInfoMap, //
        Field[] fields){
    for(Field field : fields){
        if(Modifier.isStatic(field.getModifiers())){
            continue;
        }
        JSONField fieldAnnotation = field.getAnnotation(JSONField.class);
        int ordinal = 0, serialzeFeatures = 0, parserFeatures = 0;
        String propertyName = field.getName();
        String label = null;
        if(fieldAnnotation != null){
            if(!fieldAnnotation.serialize()){
                continue;
            }
            ordinal = fieldAnnotation.ordinal();
            serialzeFeatures = SerializerFeature.of(fieldAnnotation.serialzeFeatures());
            parserFeatures = Feature.of(fieldAnnotation.parseFeatures());
            if(fieldAnnotation.name().length() != 0){
                propertyName = fieldAnnotation.name();
            }
            if(fieldAnnotation.label().length() != 0){
                label = fieldAnnotation.label();
            }
        }
        if(aliasMap != null){
            propertyName = aliasMap.get(propertyName);
            if(propertyName == null){
                continue;
            }
        }
        if(propertyNamingStrategy != null){
            propertyName = propertyNamingStrategy.translate(propertyName);
        }
        if(!fieldInfoMap.containsKey(propertyName)){
            FieldInfo fieldInfo = new FieldInfo(propertyName, null, field, clazz, null, ordinal, serialzeFeatures, parserFeatures,
                    null, fieldAnnotation, label);
            fieldInfoMap.put(propertyName, fieldInfo);
        }
    }
}
 
源代码11 项目: uavstack   文件: JavaBeanInfo.java
public static JavaBeanInfo build(Class<?> clazz, Type type, PropertyNamingStrategy propertyNamingStrategy) {
    return build(clazz, type, propertyNamingStrategy, false, TypeUtils.compatibleWithJavaBean, false);
}
 
源代码12 项目: uavstack   文件: JavaBeanInfo.java
private static void computeFields(Class<?> clazz, Type type, PropertyNamingStrategy propertyNamingStrategy, List<FieldInfo> fieldList, Field[] fields) {
    for (Field field : fields) { // public static fields
        int modifiers = field.getModifiers();
        if ((modifiers & Modifier.STATIC) != 0) {
            continue;
        }

        if ((modifiers & Modifier.FINAL) != 0) {
            Class<?> fieldType = field.getType();
            boolean supportReadOnly = Map.class.isAssignableFrom(fieldType)
                    || Collection.class.isAssignableFrom(fieldType)
                    || AtomicLong.class.equals(fieldType) //
                    || AtomicInteger.class.equals(fieldType) //
                    || AtomicBoolean.class.equals(fieldType);
            if (!supportReadOnly) {
                continue;
            }
        }

        boolean contains = false;
        for (FieldInfo item : fieldList) {
            if (item.name.equals(field.getName())) {
                contains = true;
                break; // 已经是 contains = true,无需继续遍历
            }
        }

        if (contains) {
            continue;
        }

        int ordinal = 0, serialzeFeatures = 0, parserFeatures = 0;
        String propertyName = field.getName();

        JSONField fieldAnnotation = field.getAnnotation(JSONField.class);

        if (fieldAnnotation != null) {
            if (!fieldAnnotation.deserialize()) {
                continue;
            }

            ordinal = fieldAnnotation.ordinal();
            serialzeFeatures = SerializerFeature.of(fieldAnnotation.serialzeFeatures());
            parserFeatures = Feature.of(fieldAnnotation.parseFeatures());

            if (fieldAnnotation.name().length() != 0) {
                propertyName = fieldAnnotation.name();
            }
        }

        if (propertyNamingStrategy != null) {
            propertyName = propertyNamingStrategy.translate(propertyName);
        }

        add(fieldList, new FieldInfo(propertyName, null, field, clazz, type, ordinal, serialzeFeatures, parserFeatures, null,
                fieldAnnotation, null));
    }
}
 
源代码13 项目: actframework   文件: Gh1130.java
@GetAction
@FastJsonPropertyNamingStrategy(PropertyNamingStrategy.SnakeCase)
public Gh1130Model test() {
    return new Gh1130Model();
}
 
源代码14 项目: actframework   文件: ActContext.java
public CTX fastjsonPropertyNamingStrategy(PropertyNamingStrategy strategy) {
    this.fastJsonPropertyNamingStrategy = strategy;
    return me();
}
 
源代码15 项目: actframework   文件: ActContext.java
public PropertyNamingStrategy fastjsonPropertyNamingStrategy() {
    return fastJsonPropertyNamingStrategy;
}
 
源代码16 项目: yue-library   文件: MapUtils.java
/**
 * 属性命名策略转换-驼峰命名法
 * 
 * @param param Json参数 或 POJO对象
 * @return 经过属性命名策略转换后的 JSONObject
 */
public static JSONObject toCamelCase(Object param) {
	return toPropertyNamingStrategy(param, PropertyNamingStrategy.CamelCase);
}
 
源代码17 项目: yue-library   文件: MapUtils.java
/**
 * 属性命名策略转换-下划线命名法
 * 
 * @param param Json参数 或 POJO对象
 * @return 经过属性命名策略转换后的 JSONObject
 */
public static JSONObject toUnderlineCase(Object param) {
	return toPropertyNamingStrategy(param, PropertyNamingStrategy.SnakeCase);
}
 
源代码18 项目: yue-library   文件: MapUtils.java
/**
 * 属性命名策略转换-下划线命名法
 * 
 * @param param Json参数 或 POJO对象
 * @return 经过属性命名策略转换后的 JSONObject
 */
public static JSONObject toSnakeCase(Object param) {
	return toPropertyNamingStrategy(param, PropertyNamingStrategy.SnakeCase);
}
 
源代码19 项目: actframework   文件: ActContext.java
CTX_TYPE fastjsonPropertyNamingStrategy(PropertyNamingStrategy strategy); 
源代码20 项目: actframework   文件: ActContext.java
PropertyNamingStrategy fastjsonPropertyNamingStrategy(); 
 类所在包
 类方法
 同包方法