지수형 부동소수점 validation 정규화 flag 추가 (transformer.scientific.normalize)
- SystemKeys: TRANSFROMER_SCIENTIFIC_NORMALIZE 키 및 isScientificNormalizeEnabled() 추가 - JSONMessage.isValid(): flag ON 시 toPlainString()으로 정규화 후 검증 - false positive 방지: 1.23e5(=123000)가 자릿수 제한을 우회하는 문제 차단 - false negative 방지: pointLength=0 필드에서 유효한 지수형 값이 거부되는 문제 해결 - JSONMessageValidationTest: 지수형 시나리오 4개 추가 (정규화 ON/OFF 각 케이스)
This commit is contained in:
@@ -7,6 +7,7 @@ public class SystemKeys {
|
||||
public static final String TRANSFROMER_STRING_TRIMEND = "transformer.string.trimend";
|
||||
public static final String TRANSFROMER_VALIDATION = "transformer.validation";
|
||||
public static final String TRANSFROMER_DECIMALPOINT_ADD = "transformer.decimalpoint.add";
|
||||
public static final String TRANSFROMER_SCIENTIFIC_NORMALIZE = "transformer.scientific.normalize";
|
||||
|
||||
public static final String TRANSFROMER_LAYOUT_CACHE_INIT_ONSTARTUP = "transformer.layout.cache.init.onstartup";
|
||||
public static final String TRANSFROMER_LAYOUT_CACHE_SIZE = "transformer.layout.cache.size";
|
||||
@@ -30,6 +31,7 @@ public class SystemKeys {
|
||||
private static boolean stringTrimEnd = true;
|
||||
private static boolean validationEnabled = true;
|
||||
private static boolean addDecimalpoint = false;
|
||||
private static boolean scientificNormalize = true;
|
||||
|
||||
private static boolean layoutCacheOnStartup = false;
|
||||
|
||||
@@ -64,7 +66,14 @@ public class SystemKeys {
|
||||
} catch (Exception ex) {
|
||||
addDecimalpoint = false;
|
||||
}
|
||||
|
||||
|
||||
sBoolean = System.getProperty(TRANSFROMER_SCIENTIFIC_NORMALIZE, "false");
|
||||
try {
|
||||
scientificNormalize = Boolean.valueOf(sBoolean);
|
||||
} catch (Exception ex) {
|
||||
scientificNormalize = false;
|
||||
}
|
||||
|
||||
sBoolean = System.getProperty(TRANSFROMER_LAYOUT_CACHE_INIT_ONSTARTUP, "false");
|
||||
try {
|
||||
layoutCacheOnStartup = Boolean.valueOf(sBoolean);
|
||||
@@ -93,6 +102,10 @@ public class SystemKeys {
|
||||
return addDecimalpoint;
|
||||
}
|
||||
|
||||
public static boolean isScientificNormalizeEnabled() {
|
||||
return scientificNormalize;
|
||||
}
|
||||
|
||||
public static boolean isLayoutCacheOnStartup() {
|
||||
return layoutCacheOnStartup;
|
||||
}
|
||||
|
||||
@@ -703,7 +703,15 @@ public class JSONMessage extends Message {
|
||||
}
|
||||
|
||||
private boolean isValid(String value,int length,int pointLength){
|
||||
String[] data = value.replaceAll(" ", "").split("[.]");
|
||||
String normalized = value.replaceAll(" ", "");
|
||||
if (SystemKeys.isScientificNormalizeEnabled()) {
|
||||
try {
|
||||
normalized = new BigDecimal(normalized).toPlainString();
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
String[] data = normalized.split("[.]");
|
||||
if (pointLength > 0 ){
|
||||
if (data.length ==1){
|
||||
if (data[0].length() > length - pointLength - 1 ){ //정수부 오류
|
||||
|
||||
Reference in New Issue
Block a user