GuardedSerializer .java

com.mojang.realmsclient.dto.GuardedSerializer (class): members: STRATEGY, toJson, gson, fromJson. imports: ExclusionStrategy, FieldAttributes, GsonBuilder.

com.mojang.realmsclient.dtoclass39 linescommon1.2 KB

API Surface (4)

boolean shouldSkipClass(final Class<?> clazz)
boolean shouldSkipField(final FieldAttributes field)
String toJson(final ReflectionBasedSerialization object)
String toJson(final JsonElement jsonElement)

Fields & Constants (2)

STRATEGY
gson

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

GuardedSerializer.java39 lines · Minecraft 26.3 · verbatim
1
package com.mojang.realmsclient.dto;
2
3
import com.google.gson.ExclusionStrategy;
4
import com.google.gson.FieldAttributes;
5
import com.google.gson.Gson;
6
import com.google.gson.GsonBuilder;
7
import com.google.gson.JsonElement;
8
import net.fabricmc.api.EnvType;
9
import net.fabricmc.api.Environment;
10
import org.jspecify.annotations.Nullable;
11
12
@Environment(EnvType.CLIENT)
13
public class GuardedSerializer {
14
	private static final ExclusionStrategy STRATEGY = new ExclusionStrategy() {
15
		@Override
16
		public boolean shouldSkipClass(final Class<?> clazz) {
17
			return false;
18
		}
19
20
		@Override
21
		public boolean shouldSkipField(final FieldAttributes field) {
22
			return field.getAnnotation(Exclude.class) != null;
23
		}
24
	};
25
	private final Gson gson = new GsonBuilder().addSerializationExclusionStrategy(STRATEGY).addDeserializationExclusionStrategy(STRATEGY).create();
26
27
	public String toJson(final ReflectionBasedSerialization object) {
28
		return this.gson.toJson(object);
29
	}
30
31
	public String toJson(final JsonElement jsonElement) {
32
		return this.gson.toJson(jsonElement);
33
	}
34
35
	public <T extends ReflectionBasedSerialization> @Nullable T fromJson(final String contents, final Class<T> cls) {
36
		return this.gson.fromJson(contents, cls);
37
	}
38
}
39

Decompiled Minecraft 26.3 source of GuardedSerializer (com/mojang/realmsclient/dto/GuardedSerializer.java) with Mojang official mappings, stored verbatim on the site.