use of com.google.gson.GsonBuilder in project che by eclipse.
the class StackLoaderTest method dtoShouldBeSerialized.
@Test
public void dtoShouldBeSerialized() {
StackDto stackDtoDescriptor = newDto(StackDto.class).withName("nameWorkspaceConfig");
StackComponentDto stackComponentDto = newDto(StackComponentDto.class).withName("java").withVersion("1.8");
stackDtoDescriptor.setComponents(Collections.singletonList(stackComponentDto));
stackDtoDescriptor.setTags(Arrays.asList("some teg1", "some teg2"));
stackDtoDescriptor.setDescription("description");
stackDtoDescriptor.setId("someId");
stackDtoDescriptor.setScope("scope");
stackDtoDescriptor.setCreator("Created in Codenvy");
Map<String, String> attributes = new HashMap<>();
attributes.put("attribute1", "valute attribute1");
Link link = newDto(Link.class).withHref("some url").withMethod("get").withRel("someRel").withConsumes("consumes").withProduces("produces");
HashMap<String, List<String>> projectMap = new HashMap<>();
projectMap.put("test", Arrays.asList("test", "test2"));
ProjectProblemDto projectProblem = newDto(ProjectProblemDto.class).withCode(100).withMessage("message");
SourceStorageDto sourceStorageDto = newDto(SourceStorageDto.class).withType("some type").withParameters(attributes).withLocation("location");
ProjectConfigDto projectConfigDto = newDto(ProjectConfigDto.class).withName("project").withPath("somePath").withAttributes(projectMap).withType("maven type").withDescription("some project description").withLinks(Collections.singletonList(link)).withMixins(Collections.singletonList("mixin time")).withProblems(Collections.singletonList(projectProblem)).withSource(sourceStorageDto);
EnvironmentRecipeDto environmentRecipe = newDto(EnvironmentRecipeDto.class).withContent("some content").withContentType("some content type").withType("someType");
Map<String, ServerConf2Dto> servers = new HashMap<>();
servers.put("server1Ref", newDto(ServerConf2Dto.class).withPort("8080/tcp").withProtocol("http").withProperties(singletonMap("key", "value")));
Map<String, ExtendedMachineDto> machines = new HashMap<>();
machines.put("someMachineName", newDto(ExtendedMachineDto.class).withAgents(Arrays.asList("agent1", "agent2")).withServers(servers).withAttributes(singletonMap("memoryLimitBytes", "" + 512L * 1024L * 1024L)));
EnvironmentDto environmentDto = newDto(EnvironmentDto.class).withRecipe(environmentRecipe).withMachines(machines);
CommandDto commandDto = newDto(CommandDto.class).withType("command type").withName("command name").withCommandLine("command line");
WorkspaceConfigDto workspaceConfigDto = newDto(WorkspaceConfigDto.class).withName("SomeWorkspaceConfig").withDescription("some workspace").withLinks(Collections.singletonList(link)).withDefaultEnv("some Default Env name").withProjects(Collections.singletonList(projectConfigDto)).withEnvironments(singletonMap("name", environmentDto)).withCommands(Collections.singletonList(commandDto));
stackDtoDescriptor.setWorkspaceConfig(workspaceConfigDto);
Gson GSON = new GsonBuilder().create();
GSON.fromJson(stackDtoDescriptor.toString(), StackImpl.class);
}
use of com.google.gson.GsonBuilder in project MyDiary by erttyy8821.
the class ExportAsyncTask method outputBackupJson.
private void outputBackupJson() throws IOException {
Writer writer = new FileWriter(backupJsonFilePath);
Gson gson = new GsonBuilder().create();
gson.toJson(backupManager, writer);
writer.close();
}
use of com.google.gson.GsonBuilder in project MVCHelper by LuckyJayce.
the class ABSTestCaseFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
this.inflater = inflater;
View view = inflater.inflate(R.layout.testcase, container, false);
taskHelper = new TaskHelper<>();
GsonBuilder builder = new GsonBuilder();
// 格式化输出
builder.setPrettyPrinting();
// builder.serializeNulls();
builder.addSerializationExclusionStrategy(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
// true; //按注解排除
return false;
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
// 直接排除某个类 ,return true为排除
return clazz == Gson.class || clazz == Bitmap.class;
}
}).create();
gson = builder.create();
recyclerView = (RecyclerView) view.findViewById(R.id.testcase2_recyclerView);
paramsRecyclerView = (LinearLayout) view.findViewById(R.id.testcase2_params_recyclerView);
resultTextView = (TextView) view.findViewById(R.id.testcase2_result_textView);
runButton = (Button) view.findViewById(R.id.testcase2_run_button);
resetButton = (Button) view.findViewById(R.id.testcase2_reset_button);
itemRunButton = view.findViewById(R.id.testcase2_run2_button);
resultStateTextView = (TextView) view.findViewById(R.id.testcase2_resultState_textView);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(tasksAdapter = new TasksAdapter());
// recyclerView.addItemDecoration(new DividerItemDecoration(getContext()));
//
// // paramsRecyclerView.setLayoutManager(new
// // LinearLayoutManager(getContext()));
// // paramsRecyclerView.addItemDecoration(new
// // DividerItemDecoration(getContext()));
// // paramsRecyclerView.setAdapter(paramsAdapter = new ParamsAdapter());
datas = getTestCaseDatas();
resetButton.setOnClickListener(onClickListener);
runButton.setOnClickListener(onClickListener);
itemRunButton.setOnClickListener(onClickListener);
tasksAdapter.setOnItemClickListener(onItemClickListener);
resultTextView.setOnClickListener(onClickListener);
updateRight();
return view;
}
use of com.google.gson.GsonBuilder in project MinecraftForge by MinecraftForge.
the class MetadataCollection method from.
public static MetadataCollection from(@Nullable InputStream inputStream, String sourceName) {
if (inputStream == null) {
return new MetadataCollection();
}
InputStreamReader reader = new InputStreamReader(inputStream);
try {
MetadataCollection collection;
Gson gson = new GsonBuilder().registerTypeAdapter(ArtifactVersion.class, new ArtifactVersionAdapter()).create();
JsonParser parser = new JsonParser();
JsonElement rootElement = parser.parse(reader);
if (rootElement.isJsonArray()) {
collection = new MetadataCollection();
JsonArray jsonList = rootElement.getAsJsonArray();
collection.modList = new ModMetadata[jsonList.size()];
int i = 0;
for (JsonElement mod : jsonList) {
collection.modList[i++] = gson.fromJson(mod, ModMetadata.class);
}
} else {
collection = gson.fromJson(rootElement, MetadataCollection.class);
}
collection.parseModMetadataList();
return collection;
} catch (JsonParseException e) {
FMLLog.log(Level.ERROR, e, "The mcmod.info file in %s cannot be parsed as valid JSON. It will be ignored", sourceName);
return new MetadataCollection();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of com.google.gson.GsonBuilder in project immutables by immutables.
the class JaxrsTest method propagateGsonAttributes.
@Test
public void propagateGsonAttributes() {
Gson gson = new GsonBuilder().serializeNulls().disableHtmlEscaping().setPrettyPrinting().create();
GsonOptions options = new GsonOptions(gson, true);
JsonReader reader = new JsonReader(new StringReader(""));
options.setReaderOptions(reader);
check(reader.isLenient());
JsonWriter writer = new JsonWriter(new StringWriter());
options.setWriterOptions(writer);
check(writer.isLenient());
check(!writer.isHtmlSafe());
check(writer.getSerializeNulls());
// checks pretty printing
check(gson.toJson(Collections.singletonMap("k", "v"))).is("{\n \"k\": \"v\"\n}");
}
Aggregations