本文整理汇总了Java中com.cedarsoftware.util.io.JsonWriter类的典型用法代码示例。如果您正苦于以下问题:Java JsonWriter类的具体用法?Java JsonWriter怎么用?Java JsonWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonWriter类属于com.cedarsoftware.util.io包,在下文中一共展示了JsonWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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));
}
示例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();
}
示例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));
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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);
}
示例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";
}
示例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);
}