dongzhi5587 2015-08-19 21:50
浏览 54
已采纳

将字符串数据转换为结构:插入Java AppEngine(Objectify),在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 *zcanEditEvent 
*zroleName *   organizerzisAdmin *�z�4709220381360128 
*��jjrzshowOnMessages *zcanInviteAssistants *zcanInviteOrganizers 
*zcanEditEvent *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.

  • 写回答

1条回答 默认 最新

  • dsgdg46465 2015-08-19 22:07
    关注

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

    You could use json or something.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题