Пример #1
0
  @Override
  @SuppressWarnings({"unchecked", "rawtypes"})
  public void load(Object serialized) {
    if (!(serialized instanceof Map<?, ?>)) throw new IllegalArgumentException("");

    Map<String, String[]> data = (Map<String, String[]>) serialized;
    for (Entry<String, String[]> entry : data.entrySet()) {
      String[] args = entry.getValue();
      MutableValue<?> value;
      if (args.length == 3) {
        try {
          Class<?> type = Class.forName(args[1]);
          value =
              new MutableValueImpl(
                  type, SerializationUtils.deserialize(args[2]), conversionService);
        } catch (Exception e) {
          value = new MutableValueImpl<>(String.class, args[0], conversionService);
        }
      } else {
        value = new MutableValueImpl<>(String.class, args[0], conversionService);
      }
      synchronized (values) {
        values.put(entry.getKey(), value);
      }
    }
  }
Пример #2
0
  @Override
  public Object serialize() {
    Map<String, String[]> serialized = new HashMap<>();
    for (Entry<String, MutableValue<?>> entry : values.entrySet()) {
      MutableValue<?> valueHolder = entry.getValue();
      Object value = valueHolder.getValue();
      String[] parts;
      try {
        parts =
            new String[] {
              String.valueOf(value),
              valueHolder.getType().getName(),
              SerializationUtils.serializeBase64(value)
            };
      } catch (Exception e) {
        parts = new String[] {String.valueOf(value)};
      }

      serialized.put(entry.getKey(), parts);
    }

    return serialized;
  }