How to use expansions on ContentPropertyService?


I’m using ScriptRunner to create some properties for a page, which works ok. What I can’t seem to do is use .find to return them as Groovy’s proxy class blocks .find unless I explicitly set an Expansion; however I can’t figure out the correct expansions to set.

@Field ContentPropertyService contentPropertyService = ComponentLocator.getComponent ContentPropertyService;

ContentId pageId = ContentId.of(Long.valueOf('19071593');
String myKey = 'my-key';
JsonContentProperty newProperty = JsonContentProperty.builder()
   .value(new JsonString('{\'when\': \'2021-04-08\'}'))

works, and I can see the property exists by hitting the rest endpoint

{"id":"19071593", "key":"my-key", "value":{'when': '2021-04-08'}, "version...}

but if I try getting the content from the service instead of the REST api, I get cannot call get() on collapsed object

def found = contentPropertyService.find(new Expansion(JsonContentProperty.Expansions.CONTENT), new Expansion('property'))

 log.warn "found: ${found.get()"

So what are the correct expansions to pass in? I can’t do contentPropertyService.find() because Groovy gets upset as it creates a proxy that doesn’t have access to the finder interface, so I believe I’ve got to use expansion

Answering myself in case anyone else has this issue

def found = contentPropertyService.find(new Expansion('content'), new Expansion('version')
log.warn found.get().value

gets the values.

I don’t suppose the Java APIs can have some more involved examples so that people don’t spend a day trying to use the ‘new’ APIs?