use of org.finos.legend.pure.generated.Root_meta_pure_functions_lang_KeyValue_Impl in project legend-pure by finos.
the class JsonNativeImplementation method _fromJson.
public static <T> T _fromJson(String json, Class<T> clazz, String _typeKeyName, boolean _failOnUnknownProperties, SourceInformation si, ExecutionSupport es, ConstraintsOverride constraintsHandler, RichIterable<? extends Pair<? extends String, ? extends String>> _typeLookup) {
java.lang.Class c;
String targetClassName = null;
try {
targetClassName = JavaPackageAndImportBuilder.platformJavaPackage() + ".Root_" + platform_pure_corefunctions_meta.Root_meta_pure_functions_meta_elementToPath_PackageableElement_1__String_1__String_1_(clazz, "_", es);
c = ((CompiledExecutionSupport) es).getClassLoader().loadClass(targetClassName);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Unable to find class " + targetClassName, e);
}
Map<String, Class> typeLookup = new HashMap<String, Class>();
for (Pair<? extends String, ? extends String> pair : _typeLookup) {
typeLookup.put(pair._first(), ((CompiledExecutionSupport) es).getMetadataAccessor().getClass("Root::" + pair._second()));
}
return (T) JsonDeserializer.fromJson(json, (Class<? extends Any>) clazz, new JsonDeserializationContext(new JsonDeserializationCache(), si, ((CompiledExecutionSupport) es).getProcessorSupport(), _typeKeyName, typeLookup, _failOnUnknownProperties, new ObjectFactory() {
public <U extends Any> U newObject(Class<U> clazz, Map<String, RichIterable<?>> properties) {
FastList<KeyValue> keyValues = new FastList<>();
for (Map.Entry<String, RichIterable<?>> property : properties.entrySet()) {
KeyValue keyValue = new Root_meta_pure_functions_lang_KeyValue_Impl("Anonymous");
keyValue._key(property.getKey());
for (Object value : property.getValue()) {
keyValue._valueAdd(value);
}
keyValues.add(keyValue);
}
U result = (U) Pure.newObject(clazz, keyValues, null, null, null, null, null, null, es);
result._elementOverride(constraintsHandler);
return (U) handleValidation(true, result, si, es);
}
public <T extends Any> T newUnitInstance(CoreInstance propertyType, String unitTypeString, Number unitValue) throws Exception {
CoreInstance unitRetrieved = ((CompiledExecutionSupport) es).getProcessorSupport().package_getByUserPath(unitTypeString);
if (!((CompiledExecutionSupport) es).getProcessorSupport().type_subTypeOf(unitRetrieved, propertyType)) {
throw new PureExecutionException("Cannot match unit type: " + unitTypeString + " as subtype of type: " + PackageableElement.getUserPathForPackageableElement(propertyType));
}
String unitClassName = UnitProcessor.convertToJavaCompatibleClassName(JavaPackageAndImportBuilder.buildImplUnitInstanceClassNameFromType(unitRetrieved));
java.lang.Class c = ((CompiledExecutionSupport) es).getClassLoader().loadClass("org.finos.legend.pure.generated." + unitClassName);
java.lang.Class[] paramClasses = new java.lang.Class[] { String.class, ExecutionSupport.class };
Method method = c.getMethod("_val", Number.class);
Object classInstance = c.getConstructor(paramClasses).newInstance("Anonymous_NoCounter", es);
method.invoke(classInstance, unitValue);
return (T) classInstance;
}
}));
}
Aggregations