자바 정규 표현 식 이 모든 숫자 와 일치 하 는 사례
(
[1-9]:1~9 의 숫자 와 일치 합 니 다.
\d:일치 하 는 숫자,0~9 포함;
*:\d 에 바짝 붙 어서 0 개 와 여러 개의 숫자 를 일치 시 킬 수 있 음 을 나타 낸다.
\.:소수점 과 일치 합 니 다.
? :0 개 또는 소수 점 과 일치 할 수 있 음 을 나타 낸다.
0:숫자 0 과 일치 합 니 다.
)
그 중[1-9]\d*\.?\d*1,23,34.0,56.78 과 같은 비 마이너스 정수 와 부동 소수점 을 일치 시 키 는 데 사용 합 니 다.
그 중의 0\.\d*[1-9]는 0.1,0.23,0.405 와 같은 비 마이너스 부동 소수점 과 일치 합 니 다.
private List
GetTmpFieldsList(List
FieldsList,String tmptableName,String IndexName) {
List
maps = new ArrayList<>();
for(String field :FieldsList){
// ,
if(field.toLowerCase().contains(tmptableName.toLowerCase())){
FieldList e = new FieldList();
String [] fieldArray = field.split("\\.");// string
field = field.replaceAll("\\_?\\d+", ""); //
String [] fieldArray2 = field.split("\\."); // string
Pattern p = Pattern.compile("\\d+"); //
Matcher m = p.matcher(fieldArray[1]);
if(m.find()){
int key = Integer.parseInt(m.group());
e.setCaseValue(key);
if(StringUtils.isEqual(fieldArray2[1], IndexName)){ //for BAT203
e.setField("CHECK_POSITION"); //
}else{
e.setField(fieldArray2[1]); //
}
e.setFieldName(fieldArray[1]); // e
maps.add(e);
}
/**else{
if(StringUtils.isEqual(fieldArray2[1],IndexName)){ //for BAT203
e.setField("CHECK_POSITION"); //
}else{
e.setField(fieldArray2[1]);
}
e.setFieldName(fieldArray[1]);
maps.add(e);
}**/
}
}
//Add ACE マスタ. フラグ
return maps;
}
추가 지식:fasterxml-jackson 발생 Can not deserialize instance of 이상 원인 검증이 두 안테나 에는 대량의 것 이 있다.
java.lang.IllegalArgumentException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
at [Source: N/A; line:-1,column:-1]오류 가 발생 했 습 니 다.
경험 이 있 는 사람 은 딱 봐 도 대상 속성 전환 에 이상 이 생 겼 다 는 것 을 알 수 있다.이 잘못된 근본 원인 을 찾기 위해 서
코드 로 시 뮬 레이 션 할 수 밖 에 없어 요.
/**
* Created by changle on 17/1/9.
*/
@Slf4j
public class JSONTest {
public static void main(String[] args) {
testAtoB();
//testAtoB() :Can not deserialize instance of com.test.JSONTest$Hobby out of START_ARRAY token
testBtoA();
//testBtoA() :Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
}
public static void testAtoB(){
List<Hobby> hobbies = new ArrayList<>();
Random random = new Random();
for(int i=0;i<3;i++){
Hobby hobby = new Hobby(random.nextInt()," "," ",random.nextInt(100));
hobbies.add(hobby);
}
StudentA studentA = new StudentA();
studentA.setAge(23);
studentA.setFromCity(true);
studentA.setMoney(3000);
studentA.setName(" ");
studentA.setHobbies(hobbies);
try {
String str = JSON.json(studentA);
log.info("str={}",str);
//list projo
StudentB studentB = JsonUtil.jsonObject(str, StudentB.class);
log.info("studentB.name:{}",studentB.getName());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void testBtoA(){
Random random = new Random();
Hobby hobby = new Hobby(random.nextInt(), " ", " ", random.nextInt(100));
StudentB studentB2 = new StudentB();
studentB2.setAge(23);
studentB2.setFromCity(true);
studentB2.setMoney(3000);
studentB2.setName(" ");
studentB2.setHobbies(hobby);
String str2 = null;
try {
str2 = JSON.json(studentB2);
// projo list
StudentA studentA2 = JsonUtil.jsonObject(str2, StudentA.class);
log.info("studentB.name:{}", studentA2 == null ? "" : studentA2.getName());
} catch (IOException e) {
e.printStackTrace();
}
}
@Data
public static class StudentA{
private String name;
private int age;
private long money;
private boolean isFromCity;
private List<Hobby> hobbies;
}
@Data
public static class StudentB{
private String name;
private int age;
private long money;
private boolean isFromCity;
private Hobby hobbies;
}
@Data
public static class Hobby{
private long hId;
private String hName;
private String type;
private int score;
public Hobby(){}
public Hobby(long hId,String hName,String type,int score){
this.hId = hId;
this.hName = hName;
this.type = type;
this.score = score;
}
}
}
![](https://s1.md5.ltd/image/dd29cc5c614dbc65741e45b89ab11dc3.jpg)
![](https://s1.md5.ltd/image/0709714245821378f5dc6c6decdb6e21.jpg)
결론:
Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
이 오 류 는 대상 클래스 속성 keyX 에 ArrayList 형식 이 필요 하기 때 문 입 니 다.변환 할 json 문자열 에 속성 명 keyX 가 대응 하 는 것 은 ArrayList 집합 이 아니 라 하나의 POJO 입 니 다.
Can not deserialize instance of com.test.JSONTest$Hobby out of START_ARRAY token
이 오 류 는 대상 클래스 속성 keyX 에 JSONtest$Hobby 형식 이 필요 하기 때 문 입 니 다.변환 할 json 문자열 의 속성 명 keyX 는 POJO 대상 이 아니 라 ArrayList 집합 입 니 다.
이상 의 자바 정규 표현 식 이 모든 숫자 와 일치 하 는 사례 는 바로 편집장 이 여러분 에 게 공유 한 모든 내용 입 니 다.여러분 께 참고 가 되 고 저희 도 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.