MANSCDPUtils.Builder
支持 自定义 字符串编码 默认为 GB28181 默认 GB2312 编码
This commit is contained in:
parent
d9805afe88
commit
3f6b28350a
@ -46,14 +46,12 @@ public class MANSCDPUtils {
|
||||
@Builder.Default
|
||||
@JsonIgnore
|
||||
private String encoding = GB28181Constant.CHARSET;
|
||||
private T data;
|
||||
|
||||
private T query;
|
||||
|
||||
private T response;
|
||||
|
||||
private T notify;
|
||||
|
||||
private T control;
|
||||
public XMLBuilder(T data){
|
||||
this.data = data;
|
||||
this.encoding = GB28181Constant.CHARSET;
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@ -65,20 +63,8 @@ public class MANSCDPUtils {
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
}
|
||||
|
||||
public static <T> String toQuery(XMLBuilder<T> wrapper){
|
||||
return MANSCDPUtils.toXml(wrapper.getQuery(), wrapper.encoding);
|
||||
}
|
||||
|
||||
public static <T> String toResponse(XMLBuilder<T> wrapper){
|
||||
return MANSCDPUtils.toXml(wrapper.getResponse(), wrapper.encoding);
|
||||
}
|
||||
|
||||
public static <T> String toNotify(XMLBuilder<T> wrapper){
|
||||
return MANSCDPUtils.toXml(wrapper.getNotify(), wrapper.encoding);
|
||||
}
|
||||
|
||||
public static <T> String toControl(XMLBuilder<T> wrapper){
|
||||
return MANSCDPUtils.toXml(wrapper.getControl(), wrapper.encoding);
|
||||
public static <T> String toXml(XMLBuilder<T> wrapper){
|
||||
return MANSCDPUtils.toXml(wrapper.getData(), wrapper.encoding);
|
||||
}
|
||||
|
||||
public static String toXml(Object obj, String inputCharset,String outputCharset) {
|
||||
|
@ -27,7 +27,7 @@ public class MANSCDPTest {
|
||||
.build();
|
||||
|
||||
MANSCDPUtils.XMLBuilder<KeepaliveNotifyDTO> xmlBuilder = MANSCDPUtils.XMLBuilder.<KeepaliveNotifyDTO>builder()
|
||||
.notify(keepaliveNotifyDTO)
|
||||
.data(keepaliveNotifyDTO)
|
||||
.build();
|
||||
|
||||
log.info("\n{}",MANSCDPUtils.toXml(xmlBuilder));
|
||||
@ -43,10 +43,8 @@ public class MANSCDPTest {
|
||||
.build();
|
||||
log.info("\n{}", MANSCDPUtils.toXml(catalogQueryDTO));
|
||||
|
||||
MANSCDPUtils.XMLBuilder<CatalogQueryDTO> query = MANSCDPUtils.XMLBuilder.<CatalogQueryDTO>builder()
|
||||
.query(catalogQueryDTO)
|
||||
.build();
|
||||
String serialize = MANSCDPUtils.toQuery(query);
|
||||
MANSCDPUtils.XMLBuilder<CatalogQueryDTO> query = new MANSCDPUtils.XMLBuilder(catalogQueryDTO);
|
||||
String serialize = MANSCDPUtils.toXml(query);
|
||||
log.info("\n{}", serialize);
|
||||
|
||||
CatalogQueryDTO queryDTO = MANSCDPUtils.parse(serialize, CatalogQueryDTO.class);
|
||||
@ -66,18 +64,18 @@ public class MANSCDPTest {
|
||||
.build();
|
||||
// 默认 GB2312 编码
|
||||
MANSCDPUtils.XMLBuilder<CatalogResponseDTO> response = MANSCDPUtils.XMLBuilder.<CatalogResponseDTO>builder()
|
||||
.response(catalogResponseDTO)
|
||||
.data(catalogResponseDTO)
|
||||
.build();
|
||||
serialize = MANSCDPUtils.toResponse(response);
|
||||
serialize = MANSCDPUtils.toXml(response);
|
||||
log.info("\n{}", serialize);
|
||||
CatalogResponseDTO responseDTO = MANSCDPUtils.parse(serialize, CatalogResponseDTO.class);
|
||||
log.info("{}",responseDTO);
|
||||
// UTF8 编码
|
||||
response = MANSCDPUtils.XMLBuilder.<CatalogResponseDTO>builder()
|
||||
.encoding(StandardCharsets.UTF_8.name())
|
||||
.response(catalogResponseDTO)
|
||||
.data(catalogResponseDTO)
|
||||
.build();
|
||||
serialize = MANSCDPUtils.toResponse(response);
|
||||
serialize = MANSCDPUtils.toXml(response);
|
||||
log.info("\n{}", serialize);
|
||||
responseDTO = MANSCDPUtils.parse(serialize, CatalogResponseDTO.class);
|
||||
log.info("{}",responseDTO);
|
||||
|
Loading…
Reference in New Issue
Block a user