Skip to content

Commit d68e162

Browse files
committed
fix: ignore unknown fields when deserializing for easier backwards compatability
1 parent 6866522 commit d68e162

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main/java/com/mcdiamondfire/proto/ModAPIUtility.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
public final class ModAPIUtility {
1313

14+
private static final JsonFormat.Parser JSON_PARSER = JsonFormat.parser().ignoringUnknownFields();
15+
1416
private ModAPIUtility() {
1517
// Prevent instantiation.
1618
}
@@ -50,7 +52,7 @@ public static <T extends Message> T deserializeMessage(final String json, final
5052
final String cleanedJson = jsonObject.toString();
5153

5254
final Message.Builder builder = (Message.Builder) clazz.getMethod("newBuilder").invoke(null);
53-
JsonFormat.parser().merge(cleanedJson, builder);
55+
JSON_PARSER.merge(cleanedJson, builder);
5456
//noinspection unchecked -- on the caller to ensure the type is correct.
5557
return (T) builder.build();
5658
} catch (final NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {

0 commit comments

Comments
 (0)