• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JsonWriter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.cedarsoftware.util.io.JsonWriter的典型用法代码示例。如果您正苦于以下问题:Java JsonWriter类的具体用法?Java JsonWriter怎么用?Java JsonWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JsonWriter类属于com.cedarsoftware.util.io包,在下文中一共展示了JsonWriter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testSerializeThenDeSerialize

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
@Test
public void testSerializeThenDeSerialize() throws Exception {
  DeviceTagMap tagMap = new DeviceTagMap();

  tagMap.addTag("device1", "tag1");
  tagMap.addTag("device1", "tag2");
  tagMap.addTag("device1", "tag3");
  tagMap.addTag("device1", "tag4");
  tagMap.addTag("device2", "tag1");
  tagMap.addTag("device2", "tag2");
  tagMap.addTag("device2", "tag3");
  tagMap.addTag("device2", "tag4");

  String marshalledString = toJsonString(tagMap.getTagInfoList());
  LOGGER.trace("testSerializeThenSerialize : marshalledString=\n{}", JsonWriter.formatJson(marshalledString));
  Object obj = fromJson(marshalledString,  new TypeReference<List<DeviceTagInfo>>(){});
  LOGGER.trace("testSerializeThenSerialize : unmarshalled object={}", obj);
  List<DeviceTagInfo> unmarshalledTags = (List<DeviceTagInfo>) obj;
  assertEquals(tagMap.getTagInfoList(), unmarshalledTags);
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:21,代码来源:DeviceTagsTest.java


示例2: UsersJsonProvider

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
public UsersJsonProvider() {
    jacksonAfterburner.registerModule(new AfterburnerModule());

    jsonioStreamOptions.put(JsonReader.USE_MAPS, true);
    jsonioStreamOptions.put(JsonWriter.TYPE, false);

    // set johnson JsonReader (default is `JsonProvider.provider()`)
    javax.json.spi.JsonProvider johnzonProvider = new JsonProviderImpl();
    johnzon = new org.apache.johnzon.mapper.MapperBuilder()
        .setReaderFactory(johnzonProvider.createReaderFactory(Collections.emptyMap()))
        .setGeneratorFactory(johnzonProvider.createGeneratorFactory(Collections.emptyMap()))
        .setAccessModeName("field") // default is "strict-method" which doesn't work nicely with public attributes
        .build();

    PreciseFloatSupport.enable();
}
 
开发者ID:fabienrenaud,项目名称:java-json-benchmark,代码行数:17,代码来源:UsersJsonProvider.java


示例3: encryptObject

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
@Override
public EncryptedMessage encryptObject(Object o) throws ProvisioningException {
	SecretKey key = this.cfgMgr.getSecretKey(this.cfgMgr.getCfg().getProvisioning().getQueueConfig().getEncryptionKeyName());
	if (key == null) {
		throw new ProvisioningException("Queue message encryption key not found");
	}
	
	
	try {
		String json = JsonWriter.objectToJson(o);
		
		EncryptedMessage msg = new EncryptedMessage();
		
		Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
		cipher.init(Cipher.ENCRYPT_MODE, key);
		msg.setMsg(cipher.doFinal(json.getBytes("UTF-8")));
		msg.setIv(cipher.getIV());
		return msg;
	} catch (IOException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) {
		throw new ProvisioningException("Could not encrypt message",e);
	}
	
}
 
开发者ID:TremoloSecurity,项目名称:OpenUnison,代码行数:24,代码来源:ProvisioningEngineImpl.java


示例4: testJsonIoWithNoTypeAndStream

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
@Test
public void testJsonIoWithNoTypeAndStream() throws IOException {
    PersistenceTestObject.testMigrate = false;
    PersistenceTestObject pt = new PersistenceTestObject();
    pt.setup();
    final Map<String, Object> jsonIoOptions = new HashMap<>();
    jsonIoOptions.put(JsonWriter.TYPE, false);

    String ser = SerializerDeserializer.toSerialized(pt, SerializerDeserializer.PERSISTENT, jsonIoOptions);
    LOGGER.info(ser);

    try (InputStream is = IOUtils.toInputStream(ser, "UTF-8")) {
        SerializerDeserializer.Deserialized<PersistenceTestObject> deser = SerializerDeserializer.fromSerialized(is,
                PersistenceTestObject.class, null, true);
        pt.checkEqual(deser.object);
    }
}
 
开发者ID:Talend,项目名称:daikon,代码行数:18,代码来源:SerializeDeserializeTest.java


示例5: testFlags

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
@Test
public void testFlags() {
    Property<String> element = newProperty("element");
    assertFalse(element.isFlag(Property.Flags.ENCRYPT));
    assertFalse(element.isFlag(Property.Flags.HIDDEN));
    element.addFlag(Property.Flags.ENCRYPT);
    assertTrue(element.isFlag(Property.Flags.ENCRYPT));
    assertFalse(element.isFlag(Property.Flags.HIDDEN));
    element.addFlag(Property.Flags.HIDDEN);
    assertTrue(element.isFlag(Property.Flags.ENCRYPT));
    assertTrue(element.isFlag(Property.Flags.HIDDEN));
    element.removeFlag(Property.Flags.HIDDEN);
    assertTrue(element.isFlag(Property.Flags.ENCRYPT));
    assertFalse(element.isFlag(Property.Flags.HIDDEN));
    element.removeFlag(Property.Flags.ENCRYPT);
    assertFalse(element.isFlag(Property.Flags.ENCRYPT));
    assertFalse(element.isFlag(Property.Flags.HIDDEN));

    String elementStr = JsonWriter.objectToJson(element);
    element = (Property) JsonReader.jsonToJava(elementStr);
    element.addFlag(Property.Flags.HIDDEN);

    element.addFlag(Property.Flags.ENCRYPT);
    assertTrue(element.isFlag(Property.Flags.ENCRYPT));

}
 
开发者ID:Talend,项目名称:daikon,代码行数:27,代码来源:PropertyTest.java


示例6: save

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
@Override
public void save(Player player) throws Exception {
    // Checking if file exists
    File file = new File(getStorageDirectory() + player.getAttributes().getUsername() + ".json");

    if (!file.exists()) {
        file.createNewFile();
    } else {
        file.delete();
    }

    // Generating pretty json
    Map<String, Object> args = new HashMap<>();
    args.put("JsonWriter.PRETTY_PRINT", true);
    String json = JsonWriter.objectToJson(player.getAttributes(), args);
    json = JsonWriter.formatJson(json);

    // Writing json
    FileWriter writer = new FileWriter(file);
    writer.write(json);
    writer.close();
}
 
开发者ID:PureCS,项目名称:runesource,代码行数:23,代码来源:JsonPlayerFileHandler.java


示例7: testSearchByEmail

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
@Test
public void testSearchByEmail() throws Exception {
  String email = userEntityList.get(0).getEmail();
  WebTarget service = getClient().target(getBaseURI()).queryParam(MMXUsersResource.EMAIL_PARAM, email);

  LOGGER.trace("testSearchByEmail : querying by email={}", email);

  Invocation.Builder invocationBuilder =
      service.request(MediaType.APPLICATION_JSON);
  invocationBuilder.header(MMXServerConstants.HTTP_HEADER_APP_ID, appEntity.getAppId());
  invocationBuilder.header(MMXServerConstants.HTTP_HEADER_REST_API_KEY, appEntity.getAppAPIKey());

  Response response = invocationBuilder.get();
  String body = response.readEntity(String.class);

  LOGGER.trace("testSearchByEmail : {}", JsonWriter.formatJson(body));
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:18,代码来源:MMXUsersResourceTest.java


示例8: testSerializeThenDeSerialize

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
@Test
public void testSerializeThenDeSerialize() throws Exception {
  UserTagMap tagMap = new UserTagMap();

  tagMap.addTag("user1", "tag1");
  tagMap.addTag("user1", "tag2");
  tagMap.addTag("user1", "tag3");
  tagMap.addTag("user1", "tag4");
  tagMap.addTag("user2", "tag1");
  tagMap.addTag("user2", "tag2");
  tagMap.addTag("user2", "tag3");
  tagMap.addTag("user2", "tag4");

  String marshalledString = toJsonString(tagMap.getTagInfoList());
  LOGGER.trace("testSerializeThenSerialize : marshalledString=\n{}", JsonWriter.formatJson(marshalledString));
  Object obj = fromJson(marshalledString, new TypeReference<List<UserTagInfo>>(){});
  LOGGER.trace("testSerializeThenSerialize : unmarshalled object={}", obj);
  List<UserTagInfo> unmarshalledTags = ( List<UserTagInfo>) obj;
  assertEquals(tagMap.getTagInfoList(), unmarshalledTags);
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:21,代码来源:UserTagsTest.java


示例9: get

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
@GET
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
public Response get(@Context Response response, @QueryParam(LumongoConstants.PRETTY) boolean pretty) {

	try {
		Lumongo.GetIndexesResponse getIndexesResponse = indexManager.getIndexes(Lumongo.GetIndexesRequest.newBuilder().build());

		Document mongoDocument = new org.bson.Document();
		mongoDocument.put("indexes", getIndexesResponse.getIndexNameList());
		String docString = JSONSerializers.getStrict().serialize(mongoDocument);

		if (pretty) {
			docString = JsonWriter.formatJson(docString);
		}

		return Response.status(LumongoConstants.SUCCESS).entity(docString).build();

	}
	catch (Exception e) {
		return Response.status(LumongoConstants.INTERNAL_ERROR).entity("Failed to get index names: " + e.getMessage()).build();
	}

}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:24,代码来源:IndexesResource.java


示例10: saveData

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
/**
 * Adatok mentése lemezre.
 */
private void saveData() {
    System.out.println("SaveData");
    
    String dataString = null;
    try {
        dataString = JsonWriter.objectToJson(playerData);
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    
    if (dataString != null) {
        Preferences prefs = Preferences.userRoot().node(this.getClass().getName());
        prefs.put("data", dataString);
    }
}
 
开发者ID:tiborsimon,项目名称:java-shooter-game,代码行数:19,代码来源:DataManager.java


示例11: JsonJsonIO

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
public JsonJsonIO() {

		// Configure normal formatter
		normalFormat.put(JsonWriter.SHORT_META_KEYS, Boolean.FALSE);
		normalFormat.put(JsonWriter.TYPE, Boolean.FALSE);

		// Configure pretty formatter
		prettyFormat.put(JsonWriter.PRETTY_PRINT, Boolean.TRUE);
		prettyFormat.put(JsonWriter.SHORT_META_KEYS, Boolean.FALSE);
		prettyFormat.put(JsonWriter.TYPE, Boolean.FALSE);
	}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:12,代码来源:JsonJsonIO.java


示例12: AzRule

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
public AzRule(String scopeType,String constraint, String className,ConfigManager cfgMgr,Workflow wf) throws ProvisioningException {
	if (scopeType.equalsIgnoreCase("group")) {
		scope = ScopeType.Group;
	} else if (scopeType.equalsIgnoreCase("dynamicGroup")) {
		scope = ScopeType.DynamicGroup;
	} else if (scopeType.equalsIgnoreCase("dn")) {
		scope = ScopeType.DN;
	} else if (scopeType.equalsIgnoreCase("custom")) {
	 	scope = ScopeType.Custom;
	 	
		CustomAuthorization caz = cfgMgr.getCustomAuthorizations().get(constraint);
		
		if (caz == null) {
			logger.warn("Could not find custom authorization rule : '" + className + "'");
		}
		
		String json = JsonWriter.objectToJson(caz);
		this.customAz = (CustomAuthorization) JsonReader.jsonToJava(json);
		try {
			this.customAz.setWorkflow(wf);
		} catch (AzException e) {
			throw new ProvisioningException("Can not set workflow",e);
		}
	} else if (scopeType.equalsIgnoreCase("filter")) {
		scope = ScopeType.Filter;
	}
	
	this.constraint = constraint;
	this.guid = UUID.randomUUID();
	this.className = className;
	
	while (usedGUIDS.contains(guid)) {
		this.guid = UUID.randomUUID();
	}
	
	
	

	
}
 
开发者ID:TremoloSecurity,项目名称:OpenUnison,代码行数:41,代码来源:AzRule.java


示例13: printStatus

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
/**
 * Returns status map formated as JSON
 *
 * @return JSON representation of the statuses map
 */
public String printStatus() {
    HashMap args = new HashMap();
    args.put(JsonWriter.PRETTY_PRINT, true);
    args.put(JsonWriter.DATE_FORMAT, "dd/MMM/yyyy:kk:mm:ss Z");
    args.put(JsonWriter.TYPE, false);
    return JsonWriter.objectToJson(reportStatus(), args);
}
 
开发者ID:gskorupa,项目名称:Cricket,代码行数:13,代码来源:Kernel.java


示例14: format

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
/**
 * Translates response object to JSON representation
 * @param prettyPrint pretty print JSON or not
 * @param o response object
 * @return response as JSON String
 */
public String format(boolean prettyPrint, Object o) {
    args.clear();
    args.put(JsonWriter.PRETTY_PRINT, prettyPrint);
    args.put(JsonWriter.DATE_FORMAT, "dd/MMM/yyyy:kk:mm:ss Z");
    args.put(JsonWriter.TYPE, false);
    return JsonWriter.objectToJson(o, args)+"\r\n";
}
 
开发者ID:gskorupa,项目名称:Cricket,代码行数:14,代码来源:JsonFormatter.java


示例15: getConfigAsString

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
public String getConfigAsString(ConfigSet c) {
    Map nameBlackList = new HashMap();
    ArrayList blackList = new ArrayList();
    blackList.add("host");
    blackList.add("port");
    blackList.add("threads");
    blackList.add("filter");
    blackList.add("cors");
    nameBlackList.put(Configuration.class, blackList);
    Map args = new HashMap();
    args.put(JsonWriter.PRETTY_PRINT, true);
    //args.put(JsonWriter., args)
    return JsonWriter.objectToJson(c, args);
}
 
开发者ID:gskorupa,项目名称:Cricket,代码行数:15,代码来源:Runner.java


示例16: testSchemaSerialized

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
@Test
public void testSchemaSerialized() throws Throwable {
    Schema main = SchemaBuilder.record("Main").fields().name("C").type().stringType().noDefault().name("D").type()
            .stringType().noDefault().endRecord();

    Property schemaMain = PropertyFactory.newSchema("main");
    schemaMain.setValue(main);

    String jsonMain = JsonWriter.objectToJson(schemaMain);
    System.out.println(jsonMain);
}
 
开发者ID:Talend,项目名称:daikon,代码行数:12,代码来源:SchemaTest.java


示例17: TSplunkEventCollectorWriter

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
public TSplunkEventCollectorWriter(TSplunkEventCollectorWriteOperation writeOperation, String serverUrl, String token,
        int eventsBatchSize, Schema designSchema, RuntimeContainer container) {
    this.writeOperation = writeOperation;
    this.fullRequestUrl = serverUrl.endsWith("/") ? (serverUrl + servicesSuffix) : (serverUrl + "/" + servicesSuffix);
    this.token = token;
    this.eventsBatchSize = eventsBatchSize;
    setSchema(designSchema);
    args.put(JsonWriter.TYPE, false);
}
 
开发者ID:Talend,项目名称:components,代码行数:10,代码来源:TSplunkEventCollectorWriter.java


示例18: createRequest

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
public HttpPost createRequest(List<SplunkJSONEvent> events) throws UnsupportedEncodingException {
    HttpPost request = new HttpPost(fullRequestUrl);
    request.addHeader("Authorization", "Splunk " + token);
    StringBuffer requestString = new StringBuffer();
    for (SplunkJSONEvent event : events) {
        requestString.append(JsonWriter.objectToJson(event, args));
    }
    request.setEntity(new StringEntity(requestString.toString()));
    return request;
}
 
开发者ID:Talend,项目名称:components,代码行数:11,代码来源:TSplunkEventCollectorWriter.java


示例19: getPubsubItemsBasic

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
@Test
public void getPubsubItemsBasic() throws Exception {
  Gson gson = new GsonBuilder().setPrettyPrinting().create();

  WebTarget service = getClient().target(getBaseURI() + "/" + TOPIC_NAME + "/items");

  Invocation.Builder invocationBuilder =
          service.request(MediaType.APPLICATION_JSON);
  invocationBuilder.header(MMXServerConstants.HTTP_HEADER_APP_ID, appEntity.getAppId());
  invocationBuilder.header(MMXServerConstants.HTTP_HEADER_REST_API_KEY, appEntity.getAppAPIKey());
  Response response = invocationBuilder.get();
  String jsonString = response.readEntity(String.class);
  LOGGER.trace("getPubsubItemsBasic : jsonString={}", JsonWriter.formatJson(jsonString));
  response.close();

  PubSubItemResult result = gson.fromJson(jsonString, new TypeToken<PubSubItemResult>() {
  }.getType());

  List<MMXPubSubItem> receivedList = result.getItems();


  ArrayList<MMXPubSubItem> originalList = Lists.newArrayList(Helper.getPublishedItems(appEntity.getAppId(), topicItemEntityList));
  sortAscending(originalList);

  for(int i=0; i < receivedList.size(); i++) {
    assertEquals(originalList.get(i), receivedList.get(i));
  }
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:29,代码来源:MMXTopicsItemsResourceTest.java


示例20: getPubsubItemsByUntil

import com.cedarsoftware.util.io.JsonWriter; //导入依赖的package包/类
@Test
public void getPubsubItemsByUntil() throws Exception {
  Gson gson = new GsonBuilder().setPrettyPrinting().create();
  int reverseTimeOffset = RandomUtils.nextInt(1,10);
  WebTarget service = getClient().target(getBaseURI() + "/" + TOPIC_NAME + "/items")
          .queryParam(MMXTopicsItemsResource.UNTIL_PARAM, new DateTime(testStartTime).minusDays(reverseTimeOffset).toString());

  Invocation.Builder invocationBuilder =
          service.request(MediaType.APPLICATION_JSON);
  invocationBuilder.header(MMXServerConstants.HTTP_HEADER_APP_ID, appEntity.getAppId());
  invocationBuilder.header(MMXServerConstants.HTTP_HEADER_REST_API_KEY, appEntity.getAppAPIKey());
  Response response = invocationBuilder.get();
  String jsonString = response.readEntity(String.class);
  LOGGER.trace("getPubsubItemsByUntil : jsonString={}", JsonWriter.formatJson(jsonString));
  response.close();
  PubSubItemResult result = gson.fromJson(jsonString, new TypeToken<PubSubItemResult>() {
  }.getType());

  List<MMXPubSubItem> receivedList = result.getItems();

  ArrayList<MMXPubSubItem> originalList = Lists.newArrayList(Helper.getPublishedItems(appEntity.getAppId(), topicItemEntityList));
  sortDescending(originalList);
  assertEquals(receivedList.size(), 11 - reverseTimeOffset);
  LOGGER.trace("getPubsubItemsByUntil : reverseTimeOffset={}, size = {}", reverseTimeOffset, receivedList.size());
  LOGGER.trace("getPubsubItemsByUntil : \nreceivedList=\n{}, \noriginalList=\n{}", receivedList, originalList);
  for(int i=0; i < receivedList.size(); i++) {
    assertEquals(originalList.get(i + reverseTimeOffset - 1), receivedList.get(i));
  }
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:30,代码来源:MMXTopicsItemsResourceTest.java



注:本文中的com.cedarsoftware.util.io.JsonWriter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InvalidKeyIdException类代码示例发布时间:2022-05-21
下一篇:
Java ObjectAdapter类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap