import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.util.List;
public class StringArray2StringSerialize extends JsonSerializer<List<String>> {
@Override
public void serialize(List<String> list, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
StringBuffer sb = new StringBuffer();
for (String str : list) {
if (sb.length() > 0) {
sb.append(";");
}
sb.append(str);
}
jsonGenerator.writeString(sb.toString());
}
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.util.List;
public class StringArray2StringSerialize extends JsonSerializer<List<String>> {
@Override
public void serialize(List<String> list, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
StringBuffer sb = new StringBuffer();
for (String str : list) {
if (sb.length() > 0) {
sb.append(";");
}
sb.append(str);
}
jsonGenerator.writeString(sb.toString());
}
}
//实体类的get 方法上注解
@JsonProperty("tagsNames")
@JsonSerialize(
using =StringArray2StringSerialize.class
)
public List<String> getTags() {
return tags;
}
//序列化出去后,属性名变为tagsNames,值变为带有自定义规则的字符串了
在使用bui前端框架,使用select.combox时我使用到了这个.