Search code examples
google-app-engineprotorpc

Does GAE ProtoRPC support json data field for request


I am doing development on python and GAE,

When I try to use ProtoRPC for web service, I cannot find a way to let my request contain a json format data in message. example like this:

request format:

{"owner_id":"some id","jsondata":[{"name":"peter","dob":"1911-1-1","aaa":"sth str","xxx":sth int}, {"name":...}, ...]}'       

python:

class some_function_name(messages.Message):
owner_id = messages.StringField(1, required=True)
jsondata = messages.StringField(2, required=True)      #is there a json field instead of StringField?

any other suggestion?


Solution

  • What you'd probably want to do here is use a MessageField. You can define your nested message above or within you class definition and use that as the first parameter to the field definition. For example:

    class Person(Message):
        name = StringField(1)
        dob = StringField(2)
    
    class ClassRoom(Message):
        teacher = MessageField(Person, 1)
        students = MessageField(Person, 2, repeated=True)
    

    Alternatively:

    class ClassRoom(Message):
        class Person(Message):
            ...
        ...
    

    That will work too.

    Unfortunately, if you want to store arbitrary JSON, as in any kind of JSON data without knowing ahead of time, that will not work. All fields must be predefined ahead of time.

    I hope that it's still helpful to you to use MessageField.