本文整理汇总了Java中com.cedarsoftware.util.io.JsonReader.jsonToJava方法的典型用法代码示例。如果您正苦于以下问题:Java JsonReader.jsonToJava方法的具体用法?Java JsonReader.jsonToJava怎么用?Java JsonReader.jsonToJava使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.cedarsoftware.util.io.JsonReader
的用法示例。
在下文中一共展示了JsonReader.jsonToJava方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFlags
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的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));
}
示例2: decryptObject
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
@Override
public Object decryptObject(EncryptedMessage msg) 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");
}
IvParameterSpec spec = new IvParameterSpec(msg.getIv());
Cipher cipher;
try {
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, key,spec);
byte[] bytes = cipher.doFinal(msg.getMsg());
return JsonReader.jsonToJava(new String(bytes));
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) {
throw new ProvisioningException("Could not decrypt message",e);
}
}
示例3: AzRule
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的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();
}
}
示例4: handleResponse
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
private void handleResponse(String jsonResponseString) throws IOException {
if (jsonResponseString == null || jsonResponseString.trim().isEmpty()) {
throw new IOException(getMessage("error.emptyResponse"));
}
try {
// JSONParser jsonParser = new JSONParser();
JsonObject<Object, Object> json = (JsonObject<Object, Object>) JsonReader.jsonToJava(jsonResponseString);
LOGGER.debug("Response String:/r/n" + String.valueOf(json));
lastErrorCode = ((Long) json.get("code")).intValue();
lastErrorMessage = (String) json.get("text");
if (lastErrorCode != 0) {
throw new IOException(getMessage("error.codeMessage", lastErrorCode, lastErrorMessage));
}
successCount += splunkObjectsForBulk.size();
} catch (JsonIoException e) {
throw new IOException(getMessage("error.responseParseException", e.getMessage()));
}
}
示例5: restartFlow
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
public void restartFlow(String flowId) {
FlowLog flowLog = flowLogRepository.findFirstByFlowIdOrderByCreatedDesc(flowId);
if (RESTARTABLE_FLOWS.contains(flowLog.getFlowType())) {
Optional<FlowConfiguration<?>> flowConfig = flowConfigs.stream()
.filter(fc -> fc.getClass().equals(flowLog.getFlowType())).findFirst();
Payload payload = (Payload) JsonReader.jsonToJava(flowLog.getPayload());
Flow flow = flowConfig.get().createFlow(flowId, payload.getStackId());
runningFlows.put(flow, flowLog.getFlowChainId());
if (flowLog.getFlowChainId() != null) {
flowChainHandler.restoreFlowChain(flowLog.getFlowChainId());
}
Map<Object, Object> variables = (Map<Object, Object>) JsonReader.jsonToJava(flowLog.getVariables());
flow.initialize(flowLog.getCurrentState(), variables);
RestartAction restartAction = flowConfig.get().getRestartAction(flowLog.getNextEvent());
if (restartAction != null) {
restartAction.restart(flowId, flowLog.getFlowChainId(), flowLog.getNextEvent(), payload);
return;
}
}
flowLogService.terminate(flowLog.getStackId(), flowId);
}
示例6: loadData
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
/**
* Adatok olvasása lemezről.
*/
private void loadData() {
System.out.println("LoadData");
Preferences prefs = Preferences.userRoot().node(this.getClass().getName());
String loadedString = prefs.get("data", null);
if (loadedString != null) {
try {
playerData = (PlayerData) JsonReader.jsonToJava(loadedString);
System.out.println("File loaded :)");
} catch (IOException e1) {
e1.printStackTrace();
System.exit(-1);
}
} else {
playerData = null;
}
}
示例7: deserialize
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T deserialize(String serialized) throws IOException{
if(serialized == null){
return null;
}
return (T) JsonReader.jsonToJava(serialized);
}
示例8: fromSerialized
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
/**
* Returns a materialized object from a previously serialized JSON String.
*
* @param serialized created by {@link #toSerialized(Object object, boolean persistent)}.
* @param serializedClass the class of the object being deserialized
* @param persistent see {@link #PERSISTENT} and {@link #TRANSIENT}.
* @return a {@code Properties} object represented by the {@code serialized} value.
*/
public static <T> Deserialized<T> fromSerialized(InputStream serialized, Class<T> serializedClass, PostDeserializeSetup setup,
boolean persistent) {
// serializedClass is not used, but we have it only for the generic type support so the caller
// can avoid casting.
Deserialized<T> d = new Deserialized<T>();
Map<PostDeserializeHandler, Integer> postDeserializeHandlers = new HashMap<>();
Map<Class, JsonReader.JsonClassReaderEx> readerMap = new HashMap<>();
readerMap.put(DeserializeMarker.class, new CustomReader(postDeserializeHandlers));
final AtomicBoolean migratedDeleted = new AtomicBoolean(false);// we need to pass the ref.
Map<String, Object> args = new HashMap<>();
args.put(JsonReader.CUSTOM_READER_MAP, readerMap);
args.put(JsonReader.MISSING_FIELD_HANDLER, new MissingFieldHandler(migratedDeleted));
// in case the json has not type we can try to instantiate the expected type.
if (serializedClass != null) {
args.put(JsonReader.UNKNOWN_OBJECT, serializedClass.getCanonicalName());
}
d.object = (T) JsonReader.jsonToJava(serialized, args);
boolean migrated = false;
for (Entry<PostDeserializeHandler, Integer> entry : postDeserializeHandlers.entrySet()) {
// use Entry key because the hash code may have changed
migrated |= entry.getKey().postDeserialize(entry.getValue(), setup, persistent);
}
d.migrated = migrated || migratedDeleted.get();
return d;
}
示例9: restoreFlowChain
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
public void restoreFlowChain(String flowChainId) {
FlowChainLog chainLog = flowChainLogRepository.findFirstByFlowChainIdOrderByCreatedDesc(flowChainId);
if (chainLog != null) {
Queue<Selectable> chain = (Queue<Selectable>) JsonReader.jsonToJava(chainLog.getChain());
flowChains.putFlowChain(flowChainId, chainLog.getParentFlowChainId(), chain);
if (chainLog.getParentFlowChainId() != null) {
restoreFlowChain(chainLog.getParentFlowChainId());
}
}
}
示例10: runEvolutionFromJson
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
/**
* Used for running evolutionary computation on the Sueur model simulator
* from a json file
*
* @param jsonFilename The json filename
* @param propertiesFilename If null,
* "cfg/sim/discrete/sim-properties.parameters" will be used.
* @return
*/
public static EvolutionOutputFitness runEvolutionFromJson( String jsonFilename,
String propertiesFilename )
{
// open the json file
StringBuilder b = new StringBuilder();
Scanner sc = null;
try
{
sc = new Scanner( new File( jsonFilename ) );
}
catch( FileNotFoundException e1 )
{
e1.printStackTrace();
}
// read the lines from the json file
while( sc.hasNextLine() )
{
b.append( sc.nextLine() );
}
sc.close();
// Create a JsonReader to get an Object from json file
Object jsonObj = null;
try
{
jsonObj = JsonReader.jsonToJava( b.toString() );
}
catch( IOException e )
{
e.printStackTrace();
}
// Our parameters object that was stored in json
EvolutionInputParameters p = (EvolutionInputParameters) jsonObj;
// run evolutionFromInputParameters with newly loaded object
return runEvolutionFromInputParameters( p, propertiesFilename );
}
示例11: unmarshal
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
@Override
public Object unmarshal ( String data ) throws Exception {
return JsonReader.jsonToJava(data);
}
示例12: onMessage
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
@Override
public void onMessage(Message msg) {
try {
TextMessage bmsg = (TextMessage) msg;
EncryptedMessage encMsg = (EncryptedMessage) JsonReader.jsonToJava(bmsg.getText());
WorkflowHolder wfHolder = (WorkflowHolder) this.prov.decryptObject(encMsg);
//Re-initialize the workflow
wfHolder.getWorkflow().reInit(cfgMgr);
TaskHolder th = wfHolder.getWfStack().peek();
WorkflowTask task = th.getParent().get(th.getPosition());
th.setPosition(th.getPosition() + 1);
User user = th.getCurrentUser();
if (user == null) {
user = wfHolder.getUser();
}
if (task.doTask(user, wfHolder.getRequest())) {
if (isDone(wfHolder,null)) {
wfHolder.getWorkflow().completeWorkflow();
} else {
((ProvisioningEngineImpl) this.prov).enqueue(wfHolder);
}
} else {
if (isDone(wfHolder,task)) {
wfHolder.getWorkflow().completeWorkflow();
} else {
//do nothing
}
}
msg.acknowledge();
} catch (Throwable t) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter baout = new PrintWriter(baos);
t.printStackTrace(baout);
baout.flush();
baout.close();
StringBuffer b = new StringBuffer();
b.append("Could not execute task\n").append(new String(baos.toByteArray()));
throw new RuntimeException(b.toString(),t);
}
}
示例13: load
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
/**
* Játékos adatainak betöltése. Sikeres betöltés esetén töltődik csak be az új adat az adatszerkezetbe.
*/
public void load() {
System.out.println("DataManager: load");
String filename = showFileChooser("Load");
// load file
try {
File file = new File(filename);
String string = FileUtils.readFileToString(file);
if (string != null) {
try {
playerData = (PlayerData) JsonReader.jsonToJava(string);
} catch (IOException e1) {
e1.printStackTrace();
System.exit(-1);
}
} else {
playerData = null;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*
// Read the object from file
// Save the object to file
FileInputStream fis = null;
ObjectInputStream in = null;
PlayerData p = null;
try {
fis = new FileInputStream(filename);
in = new ObjectInputStream(fis);
p = (PlayerData) in.readObject();
in.close();
playerData = null;
playerData = p;
System.out.println(p);
} catch (Exception ex) {
ex.printStackTrace();
}
*/
}
示例14: loadApprovalDetails
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
public static ApprovalDetails loadApprovalDetails(String approver,int approvalID) throws ProvisioningException {
Session session = null;
Gson gson = new Gson();
try {
session = GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getHibernateSessionFactory().openSession();
Query query = session.createQuery("SELECT apprv FROM Approvals apprv JOIN apprv.allowedApproverses allowed JOIN allowed.approvers approver WHERE apprv.id = :approval_id AND approver.userKey = :approver_id");
query.setParameter("approval_id", approvalID);
query.setParameter("approver_id", approver);
List<com.tremolosecurity.provisioning.objects.Approvals> approvals = query.list();
if (approvals.isEmpty()) {
throw new ServletException("no approval found");
}
Approvals approval = approvals.get(0);
ApprovalDetails sum = new ApprovalDetails();
sum.setApproval(approval.getId());
sum.setWorkflow(approval.getWorkflow().getId());
sum.setLabel(approval.getLabel());
sum.setUser(approval.getWorkflow().getUsers().getUserKey());
sum.setWfStart(approval.getWorkflow().getStartTs().getTime());
sum.setApprovalStart(approval.getCreateTs().getTime());
sum.setReason(approval.getWorkflow().getRequestReason());
String json = approval.getWorkflowObj();
Token token = gson.fromJson(json, Token.class);
byte[] iv = org.bouncycastle.util.encoders.Base64.decode(token.getIv());
IvParameterSpec spec = new IvParameterSpec(iv);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, GlobalEntries.getGlobalEntries().getConfigManager().getSecretKey( GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getApprovalDB().getEncryptionKey()),spec);
byte[] encBytes = org.bouncycastle.util.encoders.Base64.decode(token.getEncryptedRequest());
json = new String(cipher.doFinal(encBytes));
Workflow wf = (Workflow) JsonReader.jsonToJava(json);
sum.setUserObj(wf.getUser());
String wfName = approval.getWorkflow().getName();
sum.setWfName(wfName);
sum.setWfLabel(approval.getWorkflow().getLabel());
sum.setWfDescription(approval.getWorkflow().getDescription());
return sum;
} catch (Throwable t) {
throw new ProvisioningException("Could not load approval",t);
} finally {
if (session != null) {
session.close();
}
}
}
示例15: getWorkFlow
import com.cedarsoftware.util.io.JsonReader; //导入方法依赖的package包/类
@Override
public Workflow getWorkFlow(String name) throws ProvisioningException {
WorkflowImpl wf = this.workflows.get(name);
if (wf == null) {
throw new ProvisioningException("WorkflowImpl " + name + " does not exist");
}
wf = (WorkflowImpl) JsonReader.jsonToJava(JsonWriter.objectToJson(wf));
wf.reInit(this.cfgMgr);
if (this.sessionFactory != null) {
Connection con = null;
org.hibernate.Session session = sessionFactory.openSession();
try {
session.beginTransaction();
DateTime now = new DateTime();
Workflows workflow = new Workflows();
workflow.setName(wf.getName());
workflow.setStartTs(new Timestamp(now.getMillis()));
session.save(workflow);
wf.setId(workflow.getId());
wf.setFromDB(workflow);
session.getTransaction().commit();
} finally {
if (session != null) {
session.close();
}
}
}
return wf;
}