| 101 | /// at a missing `@Mapped` annotation or a build that ran without the |
| 102 | /// process-annotations Mojo. |
| 103 | public static String toJson(Object instance) { |
| 104 | if (instance == null) { |
| 105 | return "null"; |
| 106 | } |
| 107 | @SuppressWarnings("unchecked") |
| 108 | Mapper<Object> m = (Mapper<Object>) BY_NAME.get(instance.getClass().getName()); |
| 109 | if (m == null) { |
| 110 | throw missing(instance.getClass()); |
| 111 | } |
| 112 | Map<String, Object> root = m.toMap(instance); |
| 113 | StringBuilder sb = new StringBuilder(); |
| 114 | writeJson(sb, root); |
| 115 | return sb.toString(); |
| 116 | } |
| 117 | |
| 118 | /// Inverse of `#toJson`. Parses the JSON text and hands the resulting |
| 119 | /// Map to the registered mapper. |