ERROR: Can't construct a java object for tag:yaml.org,2002

2,700 views
Skip to first unread message

mihai onoprienco

unread,
Apr 6, 2017, 8:02:00 AM4/6/17
to SnakeYAML
Hi~!

I have this main.groovy script:

import models.*
import templates.*

import hudson.FilePath
import org.yaml.snakeyaml.Yaml

createJobs
()

void createJobs() {
 
def yaml = new Yaml()

 
// Build a list of all config files ending in .yml
 
def cwd = hudson.model.Executor.currentExecutor().getCurrentWorkspace().absolutize()
 
def configFiles = new FilePath(cwd, 'ci-repos').list('*.yml')

 
// Create a Build job for each config file
 configFiles
.each { file ->
 
def projectConfig = yaml.loadAs(file.readToString(), ProjectConfig.class)
 
def project = projectConfig.project.replaceAll(' ', '-')

 
PrepareBuildPublish.create(job("${project}-Prepare-Build-Publish"), projectConfig)
 
}
}



here is my models.ProjectConfig class:

package models

/**
 * Simple value object to store configuration information for a project.
 */

class ProjectConfig {
 
String project
 
String repo
 
String email
}

Here is the AjaxRecorder.yml:

project: AjaxRecorder
repo
: Web/AjaxRecorder
email
: my.address@company.com


When I run the main.groovy -> I get this error:

14:06:13 ERROR: Can't construct a java object for tag:yaml.org,2002:models.ProjectConfig; exception=Class not found: models.ProjectConfig
14:06:13  in 'string', line 1, column 1:
14:06:13     project: AjaxRecorder


Please help with this error. Any ideas?

Andrey Somov

unread,
Apr 6, 2017, 8:11:06 AM4/6/17
to snakeya...@googlegroups.com
Hi,
the exception says: "exception=Class not found: models.ProjectConfig"
Check why the models.ProjectConfig class is not in your classpath.

Cheers,
Andrey

--
You received this message because you are subscribed to the Google Groups "SnakeYAML" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snakeyaml-core+unsubscribe@googlegroups.com.
To post to this group, send email to snakeyaml-core@googlegroups.com.
Visit this group at https://groups.google.com/group/snakeyaml-core.
For more options, visit https://groups.google.com/d/optout.



--
Andrey Somov

mihai onoprienco

unread,
Apr 6, 2017, 8:55:15 AM4/6/17
to SnakeYAML
Thanks for lightning fast answer!
Actually your feedback gave me a clue and I found that referenced class had to be correctly renamed to models.ProjectConfig.class from models.ProjectConfig.groovy

Regards!
To unsubscribe from this group and stop receiving emails from it, send an email to snakeyaml-cor...@googlegroups.com.
To post to this group, send email to snakeya...@googlegroups.com.



--
Andrey Somov
Reply all
Reply to author
Forward
0 new messages