| 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) -> { |