@@ -36,7 +36,7 @@ private static Object castToAllowedTypes(Object arg, List<Object> pathToItem, Pa
36
36
Object fixedVal = castToAllowedTypes (val , newPathToItem , pathToType );
37
37
argFixed .put (key , fixedVal );
38
38
}
39
- return new FrozenMap (argFixed );
39
+ return new FrozenMap <> (argFixed );
40
40
} else if (arg instanceof Boolean ) {
41
41
pathToType .put (pathToItem , Boolean .class );
42
42
return arg ;
@@ -63,7 +63,7 @@ private static Object castToAllowedTypes(Object arg, List<Object> pathToItem, Pa
63
63
argFixed .add (fixedVal );
64
64
i += 1 ;
65
65
}
66
- return new FrozenList (argFixed );
66
+ return new FrozenList <> (argFixed );
67
67
} else if (arg instanceof ZonedDateTime ) {
68
68
pathToType .put (pathToItem , String .class );
69
69
return arg .toString ();
@@ -104,7 +104,7 @@ private static PathToSchemasMap getPathToSchemas(Class<Schema> cls, Object arg,
104
104
return pathToSchemasMap ;
105
105
}
106
106
107
- private static LinkedHashMap <String , Object > getProperties (Object arg , List <Object > pathToItem , PathToSchemasMap pathToSchemas ) {
107
+ private static FrozenMap <String , Object > getProperties (Object arg , List <Object > pathToItem , PathToSchemasMap pathToSchemas ) {
108
108
LinkedHashMap <String , Object > properties = new LinkedHashMap <>();
109
109
Map <String , Object > castArg = (Map <String , Object >) arg ;
110
110
for (Map .Entry <String , Object > entry : castArg .entrySet ()) {
@@ -116,7 +116,7 @@ private static LinkedHashMap<String, Object> getProperties(Object arg, List<Obje
116
116
Object castValue = getNewInstance (propertyClass , value , propertyPathToItem , pathToSchemas );
117
117
properties .put (propertyName , castValue );
118
118
}
119
- return new FrozenMap (properties );
119
+ return new FrozenMap <> (properties );
120
120
}
121
121
122
122
private static FrozenList <Object > getItems (Object arg , List <Object > pathToItem , PathToSchemasMap pathToSchemas ) {
@@ -131,37 +131,35 @@ private static FrozenList<Object> getItems(Object arg, List<Object> pathToItem,
131
131
items .add (castItem );
132
132
i += 1 ;
133
133
}
134
- return new FrozenList (items );
135
- }
136
-
137
- private static Map <Class <?>, Class <?>> getTypeToOutputClass (Class <?> cls ) {
138
- try {
139
- // This must be implemented in Schemas that are generics as a static method
140
- Method method = cls .getMethod ("typeToOutputClass" );
141
- Map <Class <?>, Class <?>> typeToOutputClass = (Map <Class <?>, Class <?>>) method .invoke (null );
142
- return typeToOutputClass ;
143
- } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e ) {
144
- return null ;
145
- }
134
+ return new FrozenList <>(items );
146
135
}
147
136
148
137
private static Object getNewInstance (Class <Schema > cls , Object arg , List <Object > pathToItem , PathToSchemasMap pathToSchemas ) {
149
- Object usedArg ;
138
+ if (!(arg instanceof Map || arg instanceof List )) {
139
+ // str, int, float, boolean, null, FileIO, bytes
140
+ return arg ;
141
+ }
150
142
if (arg instanceof Map ) {
151
- usedArg = getProperties (arg , pathToItem , pathToSchemas );
143
+ FrozenMap <String , Object > usedArg = getProperties (arg , pathToItem , pathToSchemas );
144
+ try {
145
+ Method method = cls .getMethod ("getMapOutputInstance" , FrozenMap .class );
146
+ return method .invoke (null , usedArg );
147
+ } catch (NoSuchMethodException e ) {
148
+ return usedArg ;
149
+ } catch (InvocationTargetException | IllegalAccessException e ) {
150
+ throw new RuntimeException (e );
151
+ }
152
152
} else if (arg instanceof List ) {
153
- usedArg = getItems (arg , pathToItem , pathToSchemas );
154
- } else {
155
- // str, int, float, boolean, null, FileIO, bytes
156
- return arg ;
157
- }
158
- Class <?> argType = arg . getClass () ;
159
- Map < Class <?>, Class <?>> typeToOutputClass = getTypeToOutputClass ( cls );
160
- if ( typeToOutputClass == null ) {
161
- return usedArg ;
153
+ FrozenList < Object > usedArg = getItems (arg , pathToItem , pathToSchemas );
154
+ try {
155
+ Method method = cls . getMethod ( "getListOutputInstance" , FrozenList . class );
156
+ return method . invoke ( null , usedArg ) ;
157
+ } catch ( NoSuchMethodException e ) {
158
+ return usedArg ;
159
+ } catch ( InvocationTargetException | IllegalAccessException e ) {
160
+ throw new RuntimeException ( e );
161
+ }
162
162
}
163
- Class <?> outputClass = typeToOutputClass .get (argType );
164
- // TODO add class instantiation here
165
163
return null ;
166
164
}
167
165
0 commit comments