private MethodMetadata getToJsonArrayMethod() { // Compute the relevant method name JavaSymbolName methodName = getToJsonArrayMethodName(); if (methodName == null) { return null; } final JavaType parameterType = new JavaType( Collection.class.getName(), 0, DataType.TYPE, null, Arrays.asList(destination)); // See if the type itself declared the method MethodMetadata result = getGovernorMethod(methodName, parameterType); if (result != null) { return result; } List<JavaSymbolName> parameterNames = Arrays.asList(new JavaSymbolName("collection")); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); String serializer = new JavaType("flexjson.JSONSerializer") .getNameIncludingTypeParameters(false, builder.getImportRegistrationResolver()); String root = annotationValues.getRootName() != null && annotationValues.getRootName().length() > 0 ? ".rootName(\"" + annotationValues.getRootName() + "\")" : ""; bodyBuilder.appendFormalLine( "return new " + serializer + "()" + root + ".exclude(\"*.class\")" + (annotationValues.isDeepSerialize() ? ".deepSerialize(collection)" : ".serialize(collection)") + ";"); MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder( getId(), Modifier.PUBLIC | Modifier.STATIC, methodName, new JavaType("java.lang.String"), AnnotatedJavaType.convertFromJavaTypes(parameterType), parameterNames, bodyBuilder); methodBuilder.putCustomData(CustomDataJsonTags.TO_JSON_ARRAY_METHOD, null); return methodBuilder.build(); }
public JavaSymbolName getToJsonMethodName() { String methodLabel = annotationValues.getToJsonMethod(); if (methodLabel == null || methodLabel.length() == 0) { return null; } return new JavaSymbolName(methodLabel); }
public JavaSymbolName getFromJsonArrayMethodName() { String methodLabel = annotationValues.getFromJsonArrayMethod(); if (methodLabel == null || methodLabel.length() == 0) { return null; } return new JavaSymbolName(methodLabel.replace("<TypeNamePlural>", typeNamePlural)); }
public JavaSymbolName getFromJsonMethodName() { String methodLabel = annotationValues.getFromJsonMethod(); if (methodLabel == null || methodLabel.length() == 0) { return null; } // Compute the relevant method name return new JavaSymbolName(methodLabel.replace("<TypeName>", destination.getSimpleTypeName())); }
private MethodMetadata getToJsonMethod() { // Compute the relevant method name JavaSymbolName methodName = getToJsonMethodName(); if (methodName == null) { return null; } // See if the type itself declared the method MethodMetadata result = MemberFindingUtils.getDeclaredMethod(governorTypeDetails, methodName, null); if (result != null) { return result; } InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); String serializer = new JavaType("flexjson.JSONSerializer") .getNameIncludingTypeParameters(false, builder.getImportRegistrationResolver()); String root = annotationValues.getRootName() != null && annotationValues.getRootName().length() > 0 ? ".rootName(\"" + annotationValues.getRootName() + "\")" : ""; bodyBuilder.appendFormalLine( "return new " + serializer + "()" + root + ".exclude(\"*.class\")" + (annotationValues.isDeepSerialize() ? ".deepSerialize(this)" : ".serialize(this)") + ";"); MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder( getId(), Modifier.PUBLIC, methodName, new JavaType("java.lang.String"), bodyBuilder); methodBuilder.putCustomData(CustomDataJsonTags.TO_JSON_METHOD, null); return methodBuilder.build(); }