本文整理汇总了Java中com.cedarsoftware.util.io.JsonReader类的典型用法代码示例。如果您正苦于以下问题:Java JsonReader类的具体用法?Java JsonReader怎么用?Java JsonReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonReader类属于com.cedarsoftware.util.io包,在下文中一共展示了JsonReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: UsersJsonProvider
import com.cedarsoftware.util.io.JsonReader; //导入依赖的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();
}
示例2: 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));
}
示例3: 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);
}
}
示例4: 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();
}
}
示例5: read
import com.cedarsoftware.util.io.JsonReader; //导入依赖的package包/类
@Override
public Object read(Object jOb, Deque<JsonObject<String, Object>> stack, Map<String, Object> args) {
ObjectResolver resolver = (ObjectResolver) args.get(JsonReader.OBJECT_RESOLVER);
JsonObject<String, Object> jsonObject = (JsonObject<String, Object>) jOb;
Object versionObj = jsonObject.get(VERSION_FIELD);
long version = 0;
if (versionObj != null) {
version = ((Long) versionObj).longValue();
}
resolver.traverseFields(stack, (JsonObject<String, Object>) jOb);
Object target = ((JsonObject<String, Object>) jOb).getTarget();
if (target instanceof PostDeserializeHandler) {
postDeserializeHandlers.put((PostDeserializeHandler) target, (int) version);
}
return target;
}
示例6: load
import com.cedarsoftware.util.io.JsonReader; //导入依赖的package包/类
@Override
public LoadResponse load(Player player) throws Exception {
// Checking if file exists
File file = new File(getStorageDirectory() + player.getAttributes().getUsername() + ".json");
if (!file.exists()) {
return LoadResponse.NOT_FOUND;
}
// Reading file
JsonReader reader = new JsonReader(new FileInputStream(file));
PlayerAttributes attributes = (PlayerAttributes) reader.readObject();
reader.close();
// Checking password
if (!attributes.getPassword().equals(player.getAttributes().getPassword())) {
return LoadResponse.INVALID_CREDENTIALS;
}
player.setAttributes(attributes);
return LoadResponse.SUCCESS;
}
示例7: 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()));
}
}
示例8: 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);
}
示例9: setupJsonReader
import com.cedarsoftware.util.io.JsonReader; //导入依赖的package包/类
@PostConstruct
public void setupJsonReader() {
JsonReader.assignInstantiator("com.google.common.collect.RegularImmutableBiMap", new MapFactory());
JsonReader.assignInstantiator("com.google.common.collect.RegularImmutableMap", new MapFactory());
JsonReader.assignInstantiator("com.google.common.collect.EmptyImmutableBiMap", new MapFactory());
JsonReader.assignInstantiator("com.google.common.collect.SingletonImmutableBiMap", new MapFactory());
JsonReader.assignInstantiator("java.util.Collections$EmptyMap", new MapFactory());
JsonReader.assignInstantiator("java.util.Collections$SingletonMap", new MapFactory());
JsonReader.assignInstantiator("com.google.common.collect.SingletonImmutableList", new CollectionFactory());
JsonReader.assignInstantiator("com.google.common.collect.RegularImmutableList", new CollectionFactory());
JsonReader.assignInstantiator("java.util.Collections$EmptyList", new CollectionFactory());
JsonReader.assignInstantiator("java.util.Collections$SingletonList", new CollectionFactory());
JsonReader.assignInstantiator("com.google.common.collect.RegularImmutableSet", new CollectionFactory());
JsonReader.assignInstantiator("java.util.Collections$EmptySet", new CollectionFactory());
JsonReader.assignInstantiator("java.util.Collections$SingletonSet", new CollectionFactory());
}
示例10: 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;
}
}
示例11: 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);
}
示例12: getJsonMap
import com.cedarsoftware.util.io.JsonReader; //导入依赖的package包/类
/**
* Returns the supplied Json file as a String key Object value map
* @throws IOException
* @throws FileNotFoundException
*/
public static Map<String, Object> getJsonMap(String propertiesFile) throws FileNotFoundException, IOException {
String jsonProperties = IOUtils.toString(new FileInputStream(new File(propertiesFile)));
Map<String, Object> properties = JsonReader.jsonToMaps(jsonProperties);
return properties;
}
示例13: 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;
}
示例14: loadWeaponDefinitions
import com.cedarsoftware.util.io.JsonReader; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void loadWeaponDefinitions(String fileName) throws FileNotFoundException {
// Checking if file exists
File file = new File(fileName);
if (!file.exists()) {
throw new FileNotFoundException("The weapon definitions file was not found");
}
// Reading file
JsonReader reader = new JsonReader(new FileInputStream(file));
WEAPONS = ((ArrayList<WeaponDefinition>) reader.readObject()).toArray(new WeaponDefinition[0]);
reader.close();
}
示例15: load
import com.cedarsoftware.util.io.JsonReader; //导入依赖的package包/类
public static Settings load(String fileName) throws Exception {
// Checking if file exists
File file = new File(fileName);
if (!file.exists()) {
throw new FileNotFoundException("The settings file was not found");
}
// Reading file
JsonReader reader = new JsonReader(new FileInputStream(file));
Settings settings = (Settings) reader.readObject();
reader.close();
return settings;
}