drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hnfgns <...@git.apache.org>
Subject [GitHub] drill pull request: DRILL-4275: create TransientStore for short-li...
Date Mon, 15 Feb 2016 22:43:30 GMT
Github user hnfgns commented on a diff in the pull request:

    https://github.com/apache/drill/pull/374#discussion_r52950554
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/serialization/JacksonSerializer.java
---
    @@ -0,0 +1,59 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + * <p/>
    + * http://www.apache.org/licenses/LICENSE-2.0
    + * <p/>
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.drill.exec.serialization;
    +
    +import java.io.IOException;
    +import java.util.Objects;
    +
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.fasterxml.jackson.databind.ObjectReader;
    +import com.fasterxml.jackson.databind.ObjectWriter;
    +
    +public class JacksonSerializer<T> implements InstanceSerializer<T> {
    +  private final ObjectReader reader;
    +  private final ObjectWriter writer;
    +
    +  public JacksonSerializer(final ObjectMapper mapper, final Class<T> klazz) {
    +    this.reader = mapper.reader(klazz);
    +    this.writer = mapper.writer();
    +  }
    +
    +  @Override
    +  public T deserialize(final byte[] raw) throws IOException {
    +    return reader.readValue(raw);
    +  }
    +
    +  @Override
    +  public byte[] serialize(final T instance) throws IOException {
    +    return writer.writeValueAsBytes(instance);
    +  }
    +
    +  @Override
    +  public boolean equals(Object obj) {
    +    if (obj instanceof JacksonSerializer && obj.getClass().equals(getClass()))
{
    +      final JacksonSerializer<T> other = (JacksonSerializer<T>)obj;
    +      return Objects.equals(reader, other.reader) && Objects.equals(writer, other.writer);
    +    }
    +    return false;
    +  }
    +
    +  @Override
    +  public int hashCode() {
    +    return super.hashCode();
    --- End diff --
    
    nice catch. thanks. done.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message