com.fasterxml.jackson.databind.deser.std.FromStringDeserializer Java Examples

The following examples show how to use com.fasterxml.jackson.databind.deser.std.FromStringDeserializer. 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: ObjectMappers.java    From buck with Apache License 2.0 6 votes vote down vote up
private static ObjectMapper addCustomModules(ObjectMapper mapper, boolean intern) {
  // with this mixin UnconfiguredTargetNode properties are flattened with
  // UnconfiguredTargetNodeWithDeps
  // properties
  // for prettier view. It only works for non-typed serialization.
  mapper.addMixIn(
      UnconfiguredTargetNodeWithDeps.class,
      UnconfiguredTargetNodeWithDeps.UnconfiguredTargetNodeWithDepsUnwrappedMixin.class);

  // Serialize and deserialize UnconfiguredBuildTarget as string
  SimpleModule buildTargetModule = new SimpleModule("BuildTarget");
  buildTargetModule.addSerializer(UnconfiguredBuildTarget.class, new ToStringSerializer());
  buildTargetModule.addDeserializer(
      UnconfiguredBuildTarget.class,
      new FromStringDeserializer<UnconfiguredBuildTarget>(UnconfiguredBuildTarget.class) {
        @Override
        protected UnconfiguredBuildTarget _deserialize(
            String value, DeserializationContext ctxt) {
          return UnconfiguredBuildTargetParser.parse(value, intern);
        }
      });
  mapper.registerModule(buildTargetModule);
  mapper.registerModule(forwardRelativePathModule());
  return mapper;
}
 
Example #2
Source File: ObjectMappers.java    From buck with Apache License 2.0 6 votes vote down vote up
private static SimpleModule forwardRelativePathModule() {
  SimpleModule module = new SimpleModule();
  module.addSerializer(ForwardRelativePath.class, new ToStringSerializer());
  module.addDeserializer(
      ForwardRelativePath.class,
      new FromStringDeserializer<ForwardRelativePath>(ForwardRelativePath.class) {
        @Override
        protected ForwardRelativePath _deserialize(String value, DeserializationContext ctxt)
            throws IOException {
          return ForwardRelativePath.of(value);
        }

        @Override
        protected ForwardRelativePath _deserializeFromEmptyString() throws IOException {
          return ForwardRelativePath.EMPTY;
        }
      });
  return module;
}
 
Example #3
Source File: InetJsonModule.java    From terracotta-platform with Apache License 2.0 5 votes vote down vote up
public InetJsonModule() {
  super(InetJsonModule.class.getSimpleName(), new Version(1, 0, 0, null, null, null));
  addSerializer(InetSocketAddress.class, ToStringSerializer.instance);
  addDeserializer(InetSocketAddress.class, new FromStringDeserializer<InetSocketAddress>(InetSocketAddress.class) {
    private static final long serialVersionUID = 1L;

    @Override
    protected InetSocketAddress _deserialize(String value, DeserializationContext ctxt) {
      return InetSocketAddressConverter.getInetSocketAddress(value);
    }
  });
}
 
Example #4
Source File: TerracottaJsonModule.java    From terracotta-platform with Apache License 2.0 5 votes vote down vote up
public TerracottaJsonModule() {
  super(TerracottaJsonModule.class.getSimpleName(), new Version(1, 0, 0, null, null, null));
  addSerializer(Path.class, ToStringSerializer.instance);
  addDeserializer(Path.class, new FromStringDeserializer<Path>(Path.class) {
    private static final long serialVersionUID = 1L;

    @Override
    protected Path _deserialize(String value, DeserializationContext ctxt) {
      return Paths.get(value);
    }
  });
}