Convert string data to struct: Inserted on Java AppEngine (Objectify), readed on Go AppEngine

The Intro

Hi there, I am doing a module on Go AppEngine and I have problems reading some models, that have nested models inside. The model is Party, and what I want is Permissions. But, when I get Party from datastore, Permissions struct field is of type string.

//And when I do fmt.Println(party.Permissions) show this:

%!(EXTRA string=jjrz�5878654076715008 *��jjrzshowOnMessages 
*zcanInviteAssistants *zcanInviteOrganizers *zcanEditEvent 
*zroleName *   organizerzisAdmin *�z�4709220381360128 
*��jjrzshowOnMessages *zcanInviteAssistants *zcanInviteOrganizers 
*zcanEditEvent *zroleName *ownerzisAdmin *��

What is that string? There is a way to get the original struct?

The Models

Go

type Party struct {
  Name string `datastore:"name"`
  Permissions string `datastore:"permissions"`
}

type PartyPermission struct {
  isAdmin bool
  canInviteOrganizers bool
  canInviteAssistants bool
  canEditParty bool
  showOnMessages bool
  roleName string
}

Java

@Entity
public class Party implements Cloneable, Serializable {

    @Id
    private Long id;

    private String name;

    private Map<String, PartyPermission> permissions;

    // constructor ...

    // getters, setters, etc
}

public class PartyPermission implements Serializable {

    private static final long serialVersionUID = 3019266092062869643L;

    private boolean isAdmin;

    private boolean canInviteOrganizers;

    private boolean canInviteAssistants;

    private boolean canEditEvent;

    private boolean showsOnMessages;

    private String roleName;

    // constructor

    // getters, setters, etc

}

What I've tried

I started with go, on monday 10, and I don't recognize what could be that string. I think that maybe that string was an interface and I could convert that string to an interface, and then to what I really wish, map[string]PartyPermission. So, reflection:

func (p *Party) GetPermissions() (map[string]PartyPermission) {

  iPermissions := reflect.ValueOf(p.Permissions).Interface()

  return iPermissions.(map[string]PartyPermission)  
}

That compiles great, but Go said that string couldn't be converted to another thing. Something like:

interface conversion: interface is string, not map[string]packName.PartyPermission

Thanks for your time.

Answers


You can't, you have to create a decoder for that format.

You could use json or something.


Need Your Help

Django custom model managers

django django-models django-managers

I'm confused about the correct way to use Django custom model managers - based on the docs you can create a series of managers for one model as a way of filtering. But why not create one manager cl...

How to get a function Return Type as a CodeClass2 from a method CodeElement2

c# t4 envdte

Using EnvDTE in a T4 template I can get all methods from a class easily.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.