MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / simpleDeserializeFromMap

Method simpleDeserializeFromMap

src/main/java/fieldbox/io/EDN.java:149–190  ·  view source on GitHub ↗
(Class c)

Source from the content-addressed store, hash-verified

147 }
148
149 public TagHandler simpleDeserializeFromMap(Class c) {
150 return (tag, o) -> {
151
152 try {
153 Object instance = getUnsafe().allocateInstance(c);
154
155 Map<?, ?> m = (Map) o;
156 m.entrySet().forEach(e -> {
157 String s = "";
158 Object k = e.getKey();
159 if (k instanceof Keyword) s = ((Keyword) k).getName();
160 else s = k.toString();
161
162 try {
163 Field f = c.getField(s);
164 f.setAccessible(true);
165 if (Modifier.isFinal(f.getModifiers())) {
166 long of = getUnsafe().objectFieldOffset(f);
167 if (f.getType() == Float.TYPE) getUnsafe().putFloat(instance, of, ((Number) e.getValue()).floatValue());
168 else throw new IllegalArgumentException("can't handle " + f.getType() + " / " + f + " / " + s + " " + instance);
169 } else {
170 if (f.getType() == Float.TYPE) f.set(instance, ((Number) e.getValue()).floatValue());
171 else f.set(instance, e.getValue());
172
173 }
174 } catch (NoSuchFieldException e1) {
175 e1.printStackTrace();
176 } catch (IllegalAccessException e1) {
177 e1.printStackTrace();
178 } catch (ClassCastException e1) {
179 System.err.println(" corrupt file ? " + e);
180 e1.printStackTrace();
181 }
182
183 });
184 return instance;
185 } catch (InstantiationException e) {
186 e.printStackTrace();
187 }
188 return null;
189 };
190 }
191
192 public TagHandler simpleDeserializeFromMapSafe() {
193 return (tag, o) -> {

Callers 1

EDNMethod · 0.95

Calls 9

getUnsafeMethod · 0.95
getTypeMethod · 0.80
setMethod · 0.65
forEachMethod · 0.45
getNameMethod · 0.45
toStringMethod · 0.45
getFieldMethod · 0.45
getValueMethod · 0.45
printlnMethod · 0.45

Tested by

no test coverage detected