mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add test
This commit is contained in:
parent
867ae94b74
commit
b60393d9b2
@ -421,12 +421,11 @@ public class ExceptionUtil {
|
|||||||
* @return 最尾端异常,传入null参数返回也为null
|
* @return 最尾端异常,传入null参数返回也为null
|
||||||
*/
|
*/
|
||||||
public static Throwable getRootCause(final Throwable throwable) {
|
public static Throwable getRootCause(final Throwable throwable) {
|
||||||
Throwable cause = throwable.getCause();
|
final Throwable cause = throwable.getCause();
|
||||||
if (cause != null) {
|
if (null == cause) {
|
||||||
return getRootCause(cause);
|
|
||||||
}else{
|
|
||||||
return throwable;
|
return throwable;
|
||||||
}
|
}
|
||||||
|
return getRootCause(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 looly(loolly@aliyun.com)
|
||||||
|
* Hutool is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.dromara.hutool.json;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.dromara.hutool.core.collection.ListUtil;
|
||||||
|
import org.dromara.hutool.json.serialize.JSONObjectSerializer;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class Issue3086Test {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void serializeTest() {
|
||||||
|
JSONUtil.putSerializer(TestBean.class, new TestBean());
|
||||||
|
|
||||||
|
final List<SimpleGrantedAuthority> strings = ListUtil.of(
|
||||||
|
new SimpleGrantedAuthority("ROLE_admin"),
|
||||||
|
new SimpleGrantedAuthority("ROLE_normal")
|
||||||
|
);
|
||||||
|
final TestBean testBean = new TestBean();
|
||||||
|
testBean.setAuthorities(strings);
|
||||||
|
|
||||||
|
Assertions.assertEquals("{\"authorities\":[\"ROLE_admin\",\"ROLE_normal\"]}",
|
||||||
|
JSONUtil.toJsonStr(testBean));
|
||||||
|
}
|
||||||
|
|
||||||
|
static class SimpleGrantedAuthority {
|
||||||
|
private final String role;
|
||||||
|
|
||||||
|
public SimpleGrantedAuthority(final String role) {
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthority() {
|
||||||
|
return this.role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return this.role;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
static class TestBean implements JSONObjectSerializer<TestBean> {
|
||||||
|
private Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(final JSONObject json, final TestBean testBean) {
|
||||||
|
final List<String> strings = testBean.getAuthorities()
|
||||||
|
.stream().map(SimpleGrantedAuthority::getAuthority).collect(Collectors.toList());
|
||||||
|
json.set("authorities",strings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user