Problems loading initial-data.yml in game 2.0

I am trying to connect to YABE in play1.2.4 to play in Java 2.0.4. To do this, I created initial-data.yml and tried to download it using Global.java

  #Users
 users:
     - !! models.User
         email: bob@gmail.com
         password: secret
         fullname: Bob
         isAdmin: true
 #Posts

 posts:

     - !! models.Post
         id: 1
         title: About the model layer
         postedAt: 2009-06-14
         author:     
             - !! models.User
                 email: bob@gmail.com
         content:>
                     The model has a central position in a Play!  application.  Cut ....   

My Global.java below

public void onStart(Application app) { InitialData.insert(app); } static class InitialData { public static void insert(Application app) { if(Ebean.find(User.class).findRowCount() == 0) { Map<String, List<Object>> all = (Map<String, List<Object>>)Yaml.load("initial-data.yml"); Ebean.save(all.get("users")); Ebean.save(all.get("posts")); Ebean.save(all.get("comments")); } } } 

During boot, I get the following errors

ConstructorException: null; Unable to create java object for tag: yaml.org, 2002: models.Post; exception = Unable to create property = author for JavaBean =models.Post@1 ; There is no suitable constructor with three arguments found for class models. Using

  org.yaml.snakeyaml.constructor.ConstructorException: null;  Can't construct a java object for tag: yaml.org, 2002: models.Post;  exception = Cannot create property = author for JavaBean=models.Post@1 ;  No suitable constructor with 3 arguments found for class models.User

      org.yaml.snakeyaml.constructor.Constructor $ ConstructYamlObject.construct (Constructor.java data33)

      org.yaml.snakeyaml.constructor.BaseConstructor.constructObject (BaseConstructor.java:183)

      org.yaml.snakeyaml.constructor.BaseConstructor.constructSequenceStep2 (BaseConstructor.java:277)

      org.yaml.snakeyaml.constructor.BaseConstructor.constructSequence (BaseConstructor.java:248)

      org.yaml.snakeyaml.constructor.SafeConstructor $ ConstructYamlSeq.construct (SafeConstructor.java:440)

      org.yaml.snakeyaml.constructor.BaseConstructor.constructObject (BaseConstructor.java:183)

      org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep (BaseConstructor.java:326)

      org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep (SafeConstructor.java:143)

      org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping (BaseConstructor.java:307)

      org.yaml.snakeyaml.constructor.SafeConstructor $ ConstructYamlMap.construct (SafeConstructor.java:459)

      org.yaml.snakeyaml.constructor.BaseConstructor.constructObject (BaseConstructor.java:183)

      org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument (BaseConstructor.java:142)

      org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData (BaseConstructor.java:128)

      org.yaml.snakeyaml.Yaml.loadFromReader (Yaml.java:480)

      org.yaml.snakeyaml.Yaml.load (Yaml.java:411)

Any idea why this is happening?

+4
source share
2 answers

Manuel, thanks for the help.

When I slightly changed YAML, I got it, I just deleted the β€œ-”, which is in front of β€œmodel.class”

  #Users
 users:
     - !! models.User
         email: bob@gmail.com
         password: secret
         fullname: Bob
         isAdmin: true
 #Posts

 posts:

     - !! models.Post
         id: 1
         title: About the model layer
         postedAt: 2009-06-14
         author: !! models.User
                 email: bob@gmail.com
         content:>
                     The model has a central position in a Play!  application.  Cut ....   

Any idea what "-" means?

+4
source

Some time passed when I worked with YAML, but it looks like you were re-creating a new user in Mail instead of linking to Bob.

I would try something like this:

 models.User(bob): email: bob@gmail.com password: secret fullname: Bob isAdmin: true models.Post(firstPost): id: 1 title: About the model layer postedAt: 2009-06-14 author: bob content: The model has a central position in a Play! application. 
+4
source

Source: https://habr.com/ru/post/1441943/


All Articles