小编Ama*_*ala的帖子

使用 gson 将 Java 对象转换为 JSON 字符串

我在这里找到了一些例子,它说明了如何将 json 转换为 java 对象,但在这里我需要将 Java 对象转换为 GSON

我有一个 Java 对象,现在我想将 Java 对象转换为 Gson。我怎样才能做到这一点,请参考我的代码。

Staff obj = new Staff();
Gson gson = new Gson();
Run Code Online (Sandbox Code Playgroud)

我需要将人员对象转换为 gson 对象

这是我的员工班

public class Staff {    
    private String name;
    private int age;
    private String position;
    private BigDecimal salary;
    private List<String> skills;
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

java gson

11
推荐指数
1
解决办法
2万
查看次数

如何使用 Capacitor 在 Android Native App 中获取 Angular Push Notification?

我正在开发 Angular 渐进式 Web 应用程序,当我使用ng serve它运行应用程序时,它在浏览器中运行良好,并在 Service Worker 上提供后台通知。

但相同的功能不适用于使用 Capacitor 构建工具创建的移动应用程序npx cap add android

我的firebase-service-worker.js文件:

importScripts('https://www.gstatic.com/firebasejs/5.5.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/5.5.0/firebase-messaging.js');

firebase.initializeApp({
  'messagingSenderId': '65358642427'
});

const messaging = firebase.messaging();

messaging.setBackgroundMessageHandler(function (payload) {

  var notificationTitle = JSON.parse(payload.notification).title;
  var notificationOptions = {
    body: JSON.parse(payload.notification).body
  };

  return self.registration.showNotification(notificationTitle, notificationOptions);
});
Run Code Online (Sandbox Code Playgroud)

push-notification firebase progressive-web-apps angular capacitor

3
推荐指数
1
解决办法
1724
查看次数