@Override
    public Node representData(Object data) {
      ConfigurationSerializable serializable = (ConfigurationSerializable) data;
      Map<String, Object> values = new LinkedHashMap<>();
      values.put(
          ConfigurationSerialization.SERIALIZED_TYPE_KEY,
          ConfigurationSerialization.getAlias(serializable.getClass()));
      values.putAll(serializable.serialize());

      return super.representData(values);
    }
    @Override
    public Object construct(Node node) {
      if (node.isTwoStepsConstruction()) {
        throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
      }

      Map<?, ?> raw = (Map<?, ?>) super.construct(node);

      if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
        Map<String, Object> typed = new LinkedHashMap<>(raw.size());
        for (Map.Entry<?, ?> entry : raw.entrySet()) {
          typed.put(entry.getKey().toString(), entry.getValue());
        }

        try {
          return ConfigurationSerialization.deserializeObject(typed);
        } catch (IllegalArgumentException ex) {
          throw new YAMLException("Could not deserialize object", ex);
        }
      }

      return raw;
    }
Example #3
0
 static {
   ConfigurationSerialization.registerClass(MessagePart.class);
 }
Example #4
0
 static {
   ConfigurationSerialization.registerClass(FancyMessage.class);
 }