org.apache.commons.lang3.SerializationException Java Examples

The following examples show how to use org.apache.commons.lang3.SerializationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SerializeUIView.java    From flow with Apache License 2.0 6 votes vote down vote up
public SerializeUIView() {
    Div label = new Div();
    label.setId("message");

    NativeButton button = createButton("Serialize", "serialize", event -> {
        UI ui = UI.getCurrent();
        try {
            byte[] serialize = SerializationUtils.serialize(ui);

            String result = serialize.length > 0 ?
                    "Successfully serialized ui" :
                    "Serialization failed";
            label.setText(result);
        }catch(SerializationException se) {
            label.setText(se.getMessage());
        }
    });

    add(label, button);
}
 
Example #2
Source File: ShiroRedisSerializer.java    From hdw-dubbo with Apache License 2.0 5 votes vote down vote up
public Object deserialize(byte[] bytes) {
    if (isEmpty(bytes)) {
        return null;
    }
    try {
        return deserializer.convert(bytes);
    } catch (Exception ex) {
        throw new SerializationException("Cannot deserialize", ex);
    }
}
 
Example #3
Source File: AtomicExecution.java    From rheem with Apache License 2.0 5 votes vote down vote up
/**
 * Deserialize a {@link LoadProfileEstimator} according to {@link #serialize(LoadProfileEstimator, JSONArray)}.
 *
 * @param jsonObject that should be deserialized
 * @return the {@link LoadProfileEstimator}
 */
private LoadProfileEstimator deserializeEstimator(JSONObject jsonObject) {
    if (jsonObject.has("key")) {
        final String key = jsonObject.getString("key");
        final LoadProfileEstimator estimator = LoadProfileEstimators.createFromSpecification(key, this.configuration);
        if (estimator == null) {
            throw new SerializationException("Could not create estimator for key " + key);
        }
        return estimator;
    } else if (jsonObject.has("load")) {
        final LoadProfile load = JsonSerializables.deserialize(jsonObject.getJSONObject("load"), LoadProfile.class);
        return new ConstantLoadProfileEstimator(load);
    }
    throw new SerializationException(String.format("Cannot deserialize load estimator from %s.", jsonObject));
}
 
Example #4
Source File: JsonSerializer.java    From rheem with Apache License 2.0 5 votes vote down vote up
/**
 * Deserializes an object.
 *
 * @param json that should be serialized
 * @return the deserialized object
 */
@SuppressWarnings("unchecked")
default T deserialize(JSONObject json) {
    if (JsonSerializables.isJsonNull(json)) return null;
    try {
        final Class<?> classTag = JsonSerializables.getClassTag(json);
        if (classTag == null) {
            throw new IllegalArgumentException(String.format("Cannot determine class from %s.", json));
        }
        return this.deserialize(json, (Class<? extends T>) classTag);
    } catch (ClassNotFoundException e) {
        throw new SerializationException("Could not load class.", e);
    }
}
 
Example #5
Source File: Utils.java    From RobotBuilder with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Performs a deep copy of the given object. This method is preferable to
 * the more general version because that relies on the object having a
 * default (zero-argument) constructor; however, this method only works for
 * serializable objects.
 *
 * @param <T> the type of the object to copy and return
 * @param original the object to copy
 * @return a deep copy of the given object
 */
public static <T extends Serializable> T deepCopy(T original) {
    if (original == null) {
        return null;
    }
    try {
        return SerializationUtils.clone(original);
    } catch (SerializationException notSerializable) {
        return (T) deepCopy((Object) original);
    }
}
 
Example #6
Source File: RevisionImpl.java    From pravega with Apache License 2.0 5 votes vote down vote up
public static Revision fromString(String scopedName) {
    String[] tokens = scopedName.split(":");
    if (tokens.length == 3) {
        return new RevisionImpl(Segment.fromScopedName(tokens[0]), Long.parseLong(tokens[1]), Integer.parseInt(tokens[2]));
    } else {
        throw new SerializationException("Not a valid segment name: " + scopedName);
    }
}
 
Example #7
Source File: MetaClone.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
public static <T extends Serializable> T clone(T obj){
	try {
		return SerializationUtils.clone(obj);
	}catch (SerializationException e){
		logger.error("[clone]", e);
		throw e;
	}
}
 
Example #8
Source File: CatTest.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@Test
/**
 * -Dlog4j.configurationFile=log4j2cat.xml
 */
public void testException() throws IOException {

	logger.error("[testException]", new SerializationException("exception"));

	waitForAnyKeyToExit();

}
 
Example #9
Source File: JavaSpecSerDe.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(Spec spec) throws SpecSerDeException {
  try {
    return SerializationUtils.serialize(spec);
  } catch (SerializationException e) {
    throw new SpecSerDeException(spec, e);
  }
}
 
Example #10
Source File: JavaSpecSerDe.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@Override
public Spec deserialize(byte[] spec) throws SpecSerDeException {
  try {
    return SerializationUtils.deserialize(spec);
  } catch (SerializationException e) {
    throw new SpecSerDeException(e);
  }
}
 
Example #11
Source File: TestServerAndClient.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(final String value, final OutputStream output) throws SerializationException, IOException {
    output.write(value.getBytes(StandardCharsets.UTF_8));
}
 
Example #12
Source File: SerializationUtilTest.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Test
void deserializeShouldThrowWhenNotBase64StringProvided() {
    assertThatExceptionOfType(SerializationException.class)
            .isThrownBy(() -> deserialize("abc"));
}
 
Example #13
Source File: SerializationUtilTest.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Test
void deserializeShouldThrowWhenNotSerializedBytesAreEncodedInBase64() {
    assertThatExceptionOfType(SerializationException.class)
            .isThrownBy(() -> deserialize(Base64.getEncoder().encodeToString("abc".getBytes(StandardCharsets.UTF_8))));
}
 
Example #14
Source File: TestServerAndClient.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(final String value, final OutputStream output) throws SerializationException, IOException {
    output.write(value.getBytes(StandardCharsets.UTF_8));
}
 
Example #15
Source File: JsonSerializables.java    From rheem with Apache License 2.0 3 votes vote down vote up
/**
 * Deserialize a given JSON datatype. The following cases are supported:
 * <ul>
 * <li>{@code json} is a (JSON) {@code null} value;</li>
 * <li>{@code json} is a basic (JSON) datatype;</li>
 * <li>{@code json} is a {@link Class}-tagged {@link JSONObject} that corresponds to a {@link JsonSerializable};</li>
 * <li>{@code json} is a {@link JSONArray} with {@link Class}-tagged {@link JSONObject}s that correspond to a
 * {@link JsonSerializable}s - in this case, the result type is a {@link List}.</li>
 * </ul>
 *
 * @param json the JSON data
 * @return the deserialization result
 */
public static Object deserialize(Object json) {
    if (isJsonNull(json)) return null;
    else if (isUnconvertedInstance(json)) return json;
    else if (json instanceof JSONObject) return deserialize((JSONObject) json);
    else if (json instanceof JSONArray) return deserializeAllAsList((JSONArray) json);

    throw new SerializationException(String.format("Don't know how to deserialize %s.", json));
}