All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.weaverplatform.protocol.weavermodel.InlineArraySerializer Maven / Gradle / Ivy

There is a newer version: 3.27.0
Show newest version
package com.weaverplatform.protocol.weavermodel;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.util.List;

/**
 * @author bastbijl, Sysunite 2017
 */
public class InlineArraySerializer extends StdSerializer> {

  public InlineArraySerializer() {
    this(null);
  }

  public InlineArraySerializer(Class> list) {
    super(list);
  }

  @Override
  public void serialize(List list, JsonGenerator gen, SerializerProvider provider) throws IOException {

    String body = String.join(", ", list);
    if(body.isEmpty()) {
      gen.writeString("[]");
      return;
    }

    gen.writeString("[" + body + "]");
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy