org.conqat.engine.commons.util.LineRangeSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of teamscale-commons Show documentation
Show all versions of teamscale-commons Show documentation
Provides common DTOs for Teamscale
The newest version!
package org.conqat.engine.commons.util;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import org.conqat.lib.commons.collections.CompactLines;
import org.conqat.lib.commons.string.LineRange;
import org.conqat.lib.commons.string.LineRangeStringParser;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
/**
* Custom Serializer to serialize {@link CompactLines} to string separated line ranges. See
* {@link LineRangeStringParser} for more details.
*/
public class LineRangeSerializer extends StdSerializer {
private static final long serialVersionUID = -9191867553019031697L;
public LineRangeSerializer() {
this(null);
}
private LineRangeSerializer(Class t) {
super(t);
}
@Override
public void serialize(CompactLines value, JsonGenerator jsonGen, SerializerProvider provider) throws IOException {
List compactLineRanges = LineRangeStringParser.compactifyToRanges(value);
String concatenatedCompactLineRanges = compactLineRanges.stream().map(Object::toString)
.collect(Collectors.joining(","));
jsonGen.writeString(concatenatedCompactLineRanges);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy