本文整理汇总了Java中com.cedarsoftware.util.io.JsonWriter.objectToJson方法的典型用法代码示例。如果您正苦于以下问题:Java JsonWriter.objectToJson方法的具体用法?Java JsonWriter.objectToJson怎么用?Java JsonWriter.objectToJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.cedarsoftware.util.io.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.objectToJson方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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();
}
示例3: 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));
}
示例4: 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);
}
}
示例5: 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();
}
}
示例6: 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);
}
示例7: 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";
}
示例8: 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);
}
示例9: save
import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
public FlowLog save(String flowId, String flowChanId, String key, Payload payload, Map<Object, Object> variables, Class<?> flowType,
FlowState currentState) {
String payloadJson = JsonWriter.objectToJson(payload, writeOptions);
String variablesJson = JsonWriter.objectToJson(variables, writeOptions);
FlowLog flowLog = new FlowLog(payload.getStackId(), flowId, flowChanId, key, payloadJson, payload.getClass(), variablesJson, flowType,
currentState.toString());
flowLog.setCloudbreakNodeId(cloudbreakNodeConfig.getId());
return flowLogRepository.save(flowLog);
}
示例10: export
import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
/**
* Játékos adatainak exportálása.
*/
public void export() {
System.out.println("DataManager: export");
String filename = showFileChooser("Export");
String dataString = null;
try {
dataString = JsonWriter.objectToJson(playerData);
} catch (IOException e1) {
e1.printStackTrace();
}
if (dataString != null) {
try {
FileUtils.writeStringToFile(new File(filename), dataString);
System.out.println("File exported :)");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*
// Save the object to file
FileOutputStream fos = null;
ObjectOutputStream out = null;
try {
fos = new FileOutputStream(filename);
out = new ObjectOutputStream(fos);
out.writeObject(playerData);
out.close();
} catch (Exception ex) {
ex.printStackTrace();
}
*/
}
示例11: marshal
import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
@Override
public String marshal ( Object o ) throws Exception {
return JsonWriter.objectToJson(o);
}
示例12: spitJson
import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
private void spitJson(PrintStream out, Object graphElement) {
String json = JsonWriter.objectToJson(graphElement);
out.print(json);
}
示例13: serialize
import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
public static String serialize(Object o) throws IOException{
if(o == null){
return null;
}
return JsonWriter.objectToJson(o);
}
示例14: enqueue
import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
public void enqueue(WorkflowHolder wfHolder) throws ProvisioningException {
TextMessage bm;
try {
MessageProducer mp;
MessageProducerHolder mph = null;
if (this.isInternalQueue()) {
mp = this.taskMP;
bm = taskSession.createTextMessage();
bm.setStringProperty("OriginalQueue", this.taskQueue.getQueueName());
} else {
mph = this.getTaskMessageProducer();
mp = mph.getProducer();
bm = mph.getSession().createTextMessage();
bm.setStringProperty("OriginalQueue", ((javax.jms.Queue) mph.getProducer().getDestination()).getQueueName());
}
bm.setStringProperty("WorkflowName", wfHolder.getWorkflow().getName());
bm.setStringProperty("WorkflowSubject", wfHolder.getUser().getUserID());
TaskHolder holder = wfHolder.getWfStack().peek();
WorkflowTask task = holder.getParent().get(holder.getPosition());
bm.setStringProperty("WorkflowCurrentTask", task.getLabel());
EncryptedMessage encMsg = this.encryptObject(wfHolder);
String json = JsonWriter.objectToJson(encMsg);
bm.setText(json);
try {
mp.send(bm);
} finally {
if (! this.isInternalQueue()) {
this.returnMessageProducer(mph);
}
}
} catch (Exception e) {
throw new ProvisioningException("Could not enqueue message",e);
}
}
示例15: toString
import com.cedarsoftware.util.io.JsonWriter; //导入方法依赖的package包/类
public String toString() {
return JsonWriter.objectToJson(this);
}