我正在使用Jackson来对Retrofit的Json响应进行反序列化.
我有一些数据类,其中包含Java表示为基元的某些值的默认值,因此在没有空检查的情况下访问它时不会崩溃.
这一切都在调试模式下运行良好,但是当我在启用了pro guard的版本上运行时,默认值未设置且这些值为null,导致我的应用程序在从Java访问它们时会崩溃,假设基元.
我试图添加我在网上找到的所有专业守卫规则:)但没有成功.
如果有人有任何想法,请分享.
谢谢
数据类的示例
data class RideTask(@JsonProperty(RiderFrontendConsts.PARAM_LOCATION)
val location: UserVisibleLocation?,
@JsonProperty(RiderFrontendConsts.PARAM_ETA_TS)
val etaTime: Double?,
@JsonProperty(RiderFrontendConsts.PARAM_TIME_TO_COMPLETION)
val timeToCompletion: Double?,
@JsonProperty(RiderFrontendConsts.PARAM_ETA_DESCRIPTION)
val etaDescription: String?,
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonProperty(RiderFrontendConsts.PARAM_INTERNAL_ETA_TS)
val internalEta: Long? = 0,
@JsonProperty(RiderFrontendConsts.PARAM_ETA_DESCRIPTION_LIST)
val etaDescriptionList: List<String>?,
@JsonProperty(RiderFrontendConsts.PARAM_DESCRIPTION_PREFIX)
val descriptionPrefix: String?,
@JsonProperty(RiderFrontendConsts.PARAM_WALKING_DISTANCE_DESCRIPTION)
val walkingDistanceDescription: String?,
@JsonProperty(RiderFrontendConsts.PARAM_WALKING_DISTANCE_IN_METERS)
val walkingDistanceInMeters: Int? = 0)
: Serializable
Run Code Online (Sandbox Code Playgroud)
改造和杰克逊初始化
private Retrofit getRetrofit() {
LOGGER.debug("prepare retrofit");
return new Retrofit.Builder()
.client(getHttpClient(RiderFrontendConsts.DEFAULT_TIMEOUT_IN_MILLIS))
.baseUrl(SettingsManager.getInstance(Application.getInstance()).getServerBaseUrl())
.addConverterFactory(JacksonConverterFactory.create(getObjectMapper()))
.callbackExecutor(Executors.newCachedThreadPool())
.build();
}
private static ObjectMapper getObjectMapper() {
LOGGER.debug("prepare …Run Code Online (Sandbox Code Playgroud) 我对 MongoDB 中的“生存时间”设置有疑问。我在我的实体中的 Spring-Boot 2.0.2.RELEASE 项目中创建了一个索引注释,它代表我在 MongoDB 中的文档。我将测试的“expireAfterSeconds”设置为 15 秒,但 MongoDB 在 15 秒后不会删除插入的文档。有人能告诉我我做错了什么吗?
这是 JSON 形式的 MongoDB 索引:
[
2,
{
"createdDateTime" : 1
},
"deleteAt",
"AccountServiceDB.AccountRegistration",
NumberLong(15)
]
Run Code Online (Sandbox Code Playgroud)
这是我的实体:
@Document(collection = "AccountRegistration")
public class UserRegistration {
@Id
private ObjectId _id;
@Indexed(unique = true)
private String username;
@Indexed(unique = true)
private String email;
private String user_password;
@Indexed(name = "deleteAt", expireAfterSeconds = 15)
private Date createdDateTime;
public UserRegistration() {}
public ObjectId get_id() {
return _id;
}
public void set_id(ObjectId _id) …Run Code Online (Sandbox Code Playgroud) 如果我将阻塞代码包装到 flatMap 中,这仍然是非阻塞操作吗?
例子:
public Mono<String> foo() {
Mono.empty().flatMap(obj -> {
try {
Object temp = f.get();//are the thread at this point blocked or not ?
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return Mono.just("test");
});
Run Code Online (Sandbox Code Playgroud)
所以,我认为当我将阻塞代码包装到反应式代码中时,操作仍然是非阻塞的?如果我错了,请向我解释。
spring ×2
android ×1
blocking ×1
jackson ×1
kotlin ×1
mongodb ×1
nonblocking ×1
proguard ×1
reactor ×1
spring-boot ×1