Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## 1.12.2 [TODO]
### Fixed
- Scientific notation for Doubles during raw data processing

## 1.12.0 [2025-10-23]
- Get review indicator endpoint

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.ArrayList;
Expand Down Expand Up @@ -389,7 +390,7 @@ private static void convertToCollectedVar(
// scalaire non null ?
if (value != null && !(value instanceof List<?>)) {
// idem: on garde convertOneVar(entry, String, ...)
convertOneVar(collectedVariable, String.valueOf(value), variablesMap, 1, dest);
convertOneVar(collectedVariable, getValueString(value), variablesMap, 1, dest);
}
}
}
Expand Down Expand Up @@ -462,4 +463,15 @@ public Page<LunaticJsonRawDataModel> findRawDataByCampaignIdAndDate(String campa

}

//Utils
protected static String getValueString(Object value) {
if (value instanceof Double || value instanceof Float) {
BigDecimal bd = new BigDecimal(value.toString());
return bd.stripTrailingZeros().toPlainString();
}
if (value instanceof Number) {
return value.toString();
}
return String.valueOf(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.List;
import java.util.Map;

import static fr.insee.genesis.domain.service.rawdata.LunaticJsonRawDataService.getValueString;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

class LunaticJsonRawDataServiceTest {
Expand Down Expand Up @@ -570,4 +571,38 @@ private List<String> prepareConvertTest(int rawDataSize, String campaignId, Stri
}
return interrogationIdList;
}

@Test
void getValueString_null_test(){
Object stringObject = null;

Assertions.assertThat(getValueString(stringObject)).isEqualTo("null");
}

@Test
void getValueString_string_test(){
Object stringObject = "test";

Assertions.assertThat(getValueString(stringObject)).isEqualTo("test");
}
@Test
void getValueString_int_test(){
Object intObject = 10;

Assertions.assertThat(getValueString(intObject)).isEqualTo("10");
}

@Test
void getValueString_float_test(){
Object floatObject = 10.111f;

Assertions.assertThat(getValueString(floatObject)).isEqualTo("10.111");
}

@Test
void getValueString_double_test(){
Object doubleObject = 101010101010.111d;

Assertions.assertThat(getValueString(doubleObject)).isEqualTo("101010101010.111");
}
}
Loading