Skip to content

Commit

Permalink
Merge branch 'alibaba:main' into fix/3123
Browse files Browse the repository at this point in the history
  • Loading branch information
rowstop authored Dec 31, 2024
2 parents bfb661d + 0e6bbd4 commit 4dcdbf0
Show file tree
Hide file tree
Showing 97 changed files with 1,951 additions and 1,070 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
timeout-minutes: 20
strategy:
matrix:
os: [ ubuntu-20.04 ]
os: [ ubuntu-20.04, windows-latest, macos-latest ]
java: [ 8, 11, 17, 21 ]
fail-fast: false
max-parallel: 16
Expand All @@ -33,6 +33,8 @@ jobs:
cache: maven
- name: Build with Maven and generate code coverage
run: ./mvnw -V --no-transfer-progress -Pgen-javadoc -Pgen-dokka clean package
env:
JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai
# https://github.com/marketplace/actions/codecov
- uses: codecov/codecov-action@v3
with:
Expand Down
Binary file removed .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
7 changes: 4 additions & 3 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.0/apache-maven-3.9.0-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ byte[] text = JSON.toJSONBytes(data);
import com.alibaba.fastjson2.*

val data = ... // Any
val text = text.toJSONString() // String
val bytes = text.toJSONByteArray() // ByteArray
val text = data.toJSONString() // String
val bytes = data.toJSONByteArray() // ByteArray
```

### 2.5 使用`JSONObject``JSONArray`
Expand Down
4 changes: 2 additions & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ byte[] text = JSON.toJSONBytes(data);
import com.alibaba.fastjson2.*

val data = ... // Any
val text = text.toJSONString() // String
val bytes = text.toJSONByteArray() // ByteArray
val text = data.toJSONString() // String
val bytes = data.toJSONByteArray() // ByteArray
```

### 2.5 Use `JSONObject`, `JSONArray`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void formatYYYYMMDDHHMMSS19(Blackhole bh) throws Throwable {
static String formatYYYYMMDDHHMMSS19(ZoneId zoneId, Date date) throws Throwable {
long millis = date.getTime();

final int SECONDS_PER_DAY = 60 * 60 * 24;
final long SECONDS_PER_DAY = 60 * 60 * 24;

long epochSecond = Math.floorDiv(millis, 1000L);
int offsetTotalSeconds;
Expand All @@ -90,8 +90,8 @@ static String formatYYYYMMDDHHMMSS19(ZoneId zoneId, Date date) throws Throwable
}

long localSecond = epochSecond + offsetTotalSeconds;
long localEpochDay = Math.floorDiv(localSecond, (long) SECONDS_PER_DAY);
int secsOfDay = (int) Math.floorMod(localSecond, (long) SECONDS_PER_DAY);
long localEpochDay = Math.floorDiv(localSecond, SECONDS_PER_DAY);
int secsOfDay = (int) Math.floorMod(localSecond, SECONDS_PER_DAY);
int year, month, dayOfMonth;
{
final int DAYS_PER_CYCLE = 146097;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package com.alibaba.fastjson2.internal.processor.annotation;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.annotation.JSONCompiled;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MapTest {
@Test
public void test() {
Bean bean = new Bean();
bean.values = new HashMap<>();
bean.values = new TreeMap<>();
bean.values.put("a", "101");
bean.values.put("b", "201");

String str = JSON.toJSONString(bean);
Bean bean1 = JSON.parseObject(str, Bean.class);
assertEquals(bean.values.size(), bean1.values.size());
String str1 = JSON.toJSONString(bean1);
assertEquals(str, str1);
JSONObject json1 = JSON.parseObject(str);
JSONObject json2 = JSON.parseObject(str1);
assertEquals(json1, json2);
}

@JSONCompiled
Expand All @@ -32,15 +35,17 @@ public static class Bean{
@Test
public void test1() {
Bean1 bean = new Bean1();
bean.values = new HashMap<>();
bean.values = new TreeMap<>();
bean.values.put("a", "101");
bean.values.put("b", "201");

String str = JSON.toJSONString(bean);
Bean1 bean1 = JSON.parseObject(str, Bean1.class);
assertEquals(bean.values.size(), bean1.values.size());
String str1 = JSON.toJSONString(bean1);
assertEquals(str, str1);
JSONObject json1 = JSON.parseObject(str);
JSONObject json2 = JSON.parseObject(str1);
assertEquals(json1, json2);
}

@JSONCompiled
Expand All @@ -51,15 +56,17 @@ public static class Bean1{
@Test
public void test2() {
Bean2 bean = new Bean2();
bean.values = new HashMap<>();
bean.values = new TreeMap<>();
bean.values.put("a", "101");
bean.values.put("b", "201");

String str = JSON.toJSONString(bean);
Bean2 bean1 = JSON.parseObject(str, Bean2.class);
assertEquals(bean.values.size(), bean1.values.size());
String str1 = JSON.toJSONString(bean1);
assertEquals(str, str1);
JSONObject json1 = JSON.parseObject(str);
JSONObject json2 = JSON.parseObject(str1);
assertEquals(json1, json2);
}

@JSONCompiled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import com.alibaba.fastjson2.annotation.JSONCompiled;
import org.junit.jupiter.api.Test;

import java.util.TimeZone;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DateTypeTest {
@Test
public void test() {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
Bean bean = new Bean();
bean.v01 = new java.util.Date();
bean.v02 = java.util.Calendar.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.annotation.JSONCompiled;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.util.*;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class UtilTypeTest {
@BeforeAll
static void setUp() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}

@Test
public void test() {
Bean bean = new Bean();
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/com/alibaba/fastjson2/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -3859,7 +3859,9 @@ static Object toJSON(Object object, JSONWriter.Feature... features) {
JSONFactory.createWriteContext() : JSONFactory.createWriteContext(features);
Class<?> valueClass = object.getClass();
ObjectWriter<?> objectWriter = writeContext.getObjectWriter(valueClass, valueClass);
if (objectWriter instanceof ObjectWriterAdapter && !writeContext.isEnabled(JSONWriter.Feature.ReferenceDetection)) {
if (objectWriter instanceof ObjectWriterAdapter
&& !writeContext.isEnabled(JSONWriter.Feature.ReferenceDetection)
&& (objectWriter.getFeatures() & JSONWriter.Feature.WriteClassName.mask) == 0) {
ObjectWriterAdapter objectWriterAdapter = (ObjectWriterAdapter) objectWriter;
return objectWriterAdapter.toJSONObject(object, writeContext.features);
}
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/com/alibaba/fastjson2/JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,6 @@ public byte[] toJSONBBytes(JSONWriter.Feature... features) {
* @param type specify the {@link Type} to be converted
* @since 2.0.4
*/
@SuppressWarnings("unchecked")
public <T> T to(Type type) {
return to(type, 0L);
}
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/com/alibaba/fastjson2/JSONBDump.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static com.alibaba.fastjson2.JSONB.Constants.*;
import static com.alibaba.fastjson2.JSONB.typeName;
import static com.alibaba.fastjson2.util.JDKUtils.*;
import static com.alibaba.fastjson2.util.JDKUtils.BIG_ENDIAN;

final class JSONBDump {
static Charset GB18030;
Expand Down
Loading

0 comments on commit 4dcdbf0

Please sign in to comment.