How to define a Map in a YAML file?

14,787 views
Skip to first unread message

Marc-François Cochaux-Laberge

unread,
Jan 10, 2011, 11:24:27 AM1/10/11
to play-framework
Hi,

I'm writing a little application with Play! and I would like to know
how to define a Map in a YAML file.

This is an example of a syntax I tried: (found on this group):

myMap:
? key1
: value1
? key2
: value2
? key3
: value3

I have also tried this:

myMap: [key1; value1, key2: value2, key3: value 3]

These two examples compile, but return null if I try for example
myMap.get("key1");

Any suggestions?

Thanks.

sas

unread,
Jan 10, 2011, 11:18:27 PM1/10/11
to play-framework
you should have a look at SnakeYaml documentation, that's the library
used by play

http://code.google.com/p/snakeyaml/wiki/Documentation#YAML_syntax

you have several samples there

saludos

sas


On 10 ene, 13:24, Marc-François Cochaux-Laberge

Marc-François Cochaux-Laberge

unread,
Jan 11, 2011, 12:16:39 AM1/11/11
to play-framework
I've tried everything. Nothing works. All my Maps are null, but the
other properties are not null so my Yaml file works well.

encod*ng

unread,
Jan 11, 2011, 11:08:43 AM1/11/11
to play-framework
Try it this way:

MyModel(mm):
myMap: {"key1":"value1","key2":"value2"}

On 10 Jan., 17:24, Marc-François Cochaux-Laberge

JavaPlayer

unread,
Feb 14, 2011, 1:34:27 PM2/14/11
to play-framework
I'm trying too to load a map from a yaml and nothing works. I tried
both of the suggestion above and it doesn't work. I get this message :
org.hibernate.PropertyAccessException: could not get a field value by
reflection getter of models.product.ProductAttributeLang.id

There's my definition :

Language(English):
name: English
isoCode: EN
isActive: true

product.ProductAttributeLang(ProductAttribute1LangEnSubscription1):
lang: English
name: Reccuring
description: Reccuring yearly

product.ProductAttribute(ProductAttribute1Subscription1):
available: true
productAttributeLangMap: {English :
ProductAttribute1LangEnSubscription1}

@Entity
public class ProductAttribute extends Model{

@OneToMany(mappedBy="productAttribute", cascade=CascadeType.ALL,
orphanRemoval=true)
@MapKey(name="lang")
public Map<Language, ProductAttributeLang> productAttributeLangMap;
public boolean available;
}

@Entity
public class ProductAttributeLang extends Model{
@ManyToOne
public ProductAttribute productAttribute;

@ManyToOne
public Language lang;

public String name;
public String description;
}

Is anybody know how to fix it ?

Thank you

andy petrella

unread,
Aug 18, 2011, 10:24:02 AM8/18/11
to play-fr...@googlegroups.com
I have the same problem....

The yaml document is rendered in a linked hash map and contains all entries in their own linked hash map, but when mapping on objects they are somehow ignored...

how it must be created in java:
Permission permission = new Permission()
permission.admin = true
permission.credential = new Credential()
permission.credential.connect = true
permission.credential.controllersAccess = new HashMap<String, Boolean>();
permission.credential.controllersAccess.put('Application.*', true)    //THIS WON'T BE DONE...
permission.credential.controllersAccess.put('OwnerPrivate.*', false) //NEITHER

how it should be presented in yaml:
Permission(perm):
admin: true
credential:
connect: true
controllersAccess:
? Application.*
: true
? OwnerPrivate.*
: false 

Thanks in advance (now I'm gonna try to catch the missing part or my mistakes, loading the play src in my IDE ^^)

andy
 

Federico Tolomei

unread,
Aug 18, 2011, 10:41:26 AM8/18/11
to play-fr...@googlegroups.com
Hi,
I have the exact problem discussed here [0], I also reported it in
the bugtrucker [1] but no feedback yet from developers.

[0] http://groups.google.com/group/play-framework/browse_thread/thread/58492c09c3b8848a/75fe25d2cf383252?pli=1
[1] http://play.lighthouseapp.com/projects/57987/tickets/977-unable-to-load-data-in-map-from-yml

--
skype: effe.to

andy petrella

unread,
Aug 18, 2011, 11:35:55 AM8/18/11
to play-fr...@googlegroups.com
Okay thanks,

I found the problem, and a way to resolve it. I posted it in the ticket...

Don't know how to do more unless do it myself... what I'll probably do :/
Reply all
Reply to author
Forward
0 new messages