public void setValue(Object value, ValueFields valueFields) { try { valueFields.setTextValue(objectMapper.writeValueAsString(value)); } catch (JsonProcessingException e) { logger.error("Error writing json variable " + valueFields.getName(), e); } }
public byte[] serialize(Object value, ValueFields valueFields) { if (value == null) { return null; } String json = null; try{ json = objectMapper.writeValueAsString(value); } catch (JsonProcessingException e) { logger.error("Error writing long json variable " + valueFields.getName(), e); } try { return json.getBytes("utf-8"); } catch (Exception e) { throw new ActivitiException("Error getting bytes from json variable", e); } }
public Object deserialize(byte[] bytes, ValueFields valueFields) { Object jsonValue = null; if(jsonValue==null) { try { jsonValue = objectMapper.readTree(bytes); } catch (Exception e) { logger.error("Error reading json variable " + valueFields.getName(), e); } } if(jsonValue!=null && StringUtils.isNotBlank(javaClassFieldForJackson) ) { //can find type so long as JsonTypeInfo annotation on the class - see https://stackoverflow.com/a/28384407/9705485 JsonNode classNode = ((JsonNode)jsonValue).get(javaClassFieldForJackson); if(classNode != null) { final String type = classNode.asText(); Class<?> cls = null; try { cls = Class.forName(type, false, this.getClass().getClassLoader()); } catch (ClassNotFoundException e) { logger.warn("Unable to obtain type for json variable object " + valueFields.getName(), e); } if(cls!=null) { jsonValue = objectMapper.convertValue(jsonValue, cls); } } } return jsonValue; } }
public Object deserialize(byte[] bytes, ValueFields valueFields) { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); try { ObjectInputStream ois = createObjectInputStream(bais); Object deserializedObject = ois.readObject(); return deserializedObject; } catch (Exception e) { throw new ActivitiException("Couldn't deserialize object in variable '"+valueFields.getName()+"'", e); } finally { IoUtil.closeSilently(bais); } }
public Object getValue(ValueFields valueFields) { Object jsonValue = null; if (valueFields.getTextValue() != null && valueFields.getTextValue().length() > 0) { if(jsonValue==null) { try { jsonValue = objectMapper.readTree(valueFields.getTextValue()); } catch (Exception e) { logger.error("Error reading json variable " + valueFields.getName(), e); } } if(jsonValue!=null && StringUtils.isNotBlank(javaClassFieldForJackson) ) { //can find type so long as JsonTypeInfo annotation on the class - see https://stackoverflow.com/a/28384407/9705485 JsonNode classNode = ((JsonNode)jsonValue).get(javaClassFieldForJackson); if(classNode != null) { final String type = classNode.asText(); Class<?> cls = null; try { cls = Class.forName(type, false, this.getClass().getClassLoader()); } catch (ClassNotFoundException e) { logger.warn("Unable to obtain type for json variable object " + valueFields.getName(), e); } if(cls!=null) { jsonValue = objectMapper.convertValue(jsonValue, cls); } } } } return jsonValue; }
public byte[] serialize(Object value, ValueFields valueFields) { if (value == null) { return null; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try { oos = createObjectOutputStream(baos); oos.writeObject(value); } catch (Exception e) { throw new ActivitiException("Couldn't serialize value '"+value+"' in variable '"+valueFields.getName()+"'", e); } finally { IoUtil.closeSilently(oos); } return baos.toByteArray(); }
public Object getValue(ValueFields valueFields) { JsonNode jsonValue = null; if (valueFields.getTextValue() != null && valueFields.getTextValue().length() > 0) { try { jsonValue = objectMapper.readTree(valueFields.getTextValue()); } catch (Exception e) { logger.error("Error reading json variable " + valueFields.getName(), e); } } return jsonValue; }
public Object deserialize(byte[] bytes, ValueFields valueFields) { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); try { ObjectInputStream ois = createObjectInputStream(bais); Object deserializedObject = ois.readObject(); return deserializedObject; } catch (Exception e) { throw new ActivitiException("Couldn't deserialize object in variable '"+valueFields.getName()+"'", e); } finally { IoUtil.closeSilently(bais); } }
public static byte[] serialize(Object value, ValueFields valueFields) { if(value == null) { return null; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream ois = null; try { ois = createObjectOutputStream(baos); ois.writeObject(value); } catch (Exception e) { throw new ActivitiException("Couldn't serialize value '"+value+"' in variable '"+valueFields.getName()+"'", e); } finally { IoUtil.closeSilently(ois); } return baos.toByteArray(); }
public byte[] serialize(Object value, ValueFields valueFields) { if (value == null) { return null; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try { oos = createObjectOutputStream(baos); oos.writeObject(value); } catch (Exception e) { throw new ActivitiException("Couldn't serialize value '"+value+"' in variable '"+valueFields.getName()+"'", e); } finally { IoUtil.closeSilently(oos); } return baos.toByteArray(); }
public Object getValue(ValueFields valueFields) { Object cachedObject = valueFields.getCachedValue(); if (cachedObject!=null) { return cachedObject; } byte[] bytes = (byte[]) super.getValue(valueFields); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); Object deserializedObject; try { ObjectInputStream ois = createObjectInputStream(bais); deserializedObject = ois.readObject(); valueFields.setCachedValue(deserializedObject); if (valueFields instanceof VariableInstanceEntity) { Context .getCommandContext() .getDbSqlSession() .addDeserializedObject(deserializedObject, bytes, (VariableInstanceEntity) valueFields); } } catch (Exception e) { throw new ActivitiException("Couldn't deserialize object in variable '"+valueFields.getName()+"'", e); } finally { IoUtil.closeSilently(bais); } return deserializedObject; }
throw new ActivitiException("coudn't deserialize object in variable '"+valueFields.getName()+"'", e); } finally { IoUtil.closeSilently(bais);