我正尝试使用Java代码读取yaml
文件内容,但无法使用Java模型类构造Java对象
请找到我的person.yaml
文件
name: Joe
phone: 111-111-11111
address: Park Dr, Charlie Hill
请找到我的模特班
public class Person {
private String name;
private String phone;
private String address;
}
请找到我的服务方法:
public class PersonsService {
public static void main(String args[]) throws IOException {
Yaml yaml = new Yaml();
try (InputStream in = PersonsService.class
.getResourceAsStream("person.yaml")) {
Person person = yaml.loadAs(in, Person.class);
System.out.println(person);
}
}
}
我收到以下错误:
Exception in thread "main" Can't construct a java object for tag:yaml.org,2002:com.javaproject.snakeyaml.model.Person; exception=Cannot create property=name for JavaBean=com.javaproject.snakeyaml.model.Person@77a567e1; No JavaBean properties found in com.javaproject.snakeyaml.model.Person
在“阅读器”的第1行,第1列: 姓名:乔 ^
答案 0 :(得分:1)
错误说明了所有问题:
无法为tag:yaml.org,2002:com.javaproject.snakeyaml.model.PersoN构造Java对象...在com.javaproject.snakeyaml.model.Person中找不到JavaBean属性
因此,您必须为pipeline {
agent { label "dockercon2"}
stages {
stage('checkout_stage'){
steps {
sh "id && whoami"
checkout([$class: 'GitSCM',
branches: [[name: "*/${env.SOURCE_BRANCH}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CleanBeforeCheckout'],
[$class: 'PerBuildTag'],
[$class: 'IgnoreNotifyCommit'],
[$class: 'PreBuildMerge',
options: [mergeRemote: 'origin', mergeTarget: "${gitTargetbranch()}"]]],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'https_gitlab_clone_credential', name: 'origin', refspec: '+refs/heads/testing_pipeline:refs/remotes/origin/testing_pipeline', url: "${gitUrl()}"]]])
git branch: "${gitSourcebranch()}", credentialsId: 'https_gitlab_clone_credential', url: "${gitUrl()}"
withCredentials([usernamePassword(credentialsId: 'https_gitlab_clone_credential', passwordVariable: 'bb_pass', usernameVariable: 'bb_user')])
{
sh "figlet 'wazzup'"
sh "figlet 'i am on'"
sh "git config credential.username ${UserName()}"
sh "git config credential.helper ${Gitlab_Pass()}"
//sh "git config --global user.email ${UserEmail()}"
sh "git config --global user.name ${UserName()}"
//sh "set +x /bin/sh -c \"echo ${ansibleVaultCredentials()}>vault_passwd.txt\""
sh "set +x; echo ${ansibleVaultCredentials()} >> vault_passwd.txt"
sh "echo pass"
sh "cat vault_passwd.txt"
sh "ansible-vault decrypt --vault-password-file vault_passwd.txt test.sh && sh test.sh"
}// closing withCredential
}// steps of checkout_stage
}// EDITED: Closing the checkout_stage block
stage('creating_PR') {
steps {
when {
step (currentBuild.result == "SUCCESS")
}
triggers {
bitbucketServer(bitbucketpr(projectPath: "${gitUrl()}",
cron:'H/15 * * * *',
credentialsId:'bitbucket_glone_cred',
username:"${bb_user}",
password:"${bb_pass}",
repositoryOwner:'Atul',
repositoryName:'valutstorage',
branchesFilter:"${gitSourcebranch()}",
branchesFilterBySCMIncludes:false,
ciKey:'jenkins',
ciName:'jenkins',
ciSkipPhrases:'',
checkDestinationCommit:false,
approveIfSuccess:false,
cancelOutdatedJobs:true,
commentTrigger:''))
}
}
}
} // Main stages block closer
} // Pipeline closer
类提供getter和setter,以便库将使用它们来为Person
类对象设置值。可以在here中找到有关JavaBeans属性的更多信息。