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 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c