Skip to content

Commit b0d7144

Browse files
authored
fix(openchallenges): support null value for challenge.platform (SMR-490) (Sage-Bionetworks#3490)
1 parent 61c0f8a commit b0d7144

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

apps/openchallenges/challenge-service/src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/mapper/ChallengeJsonLdMapper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ public ChallengeJsonLdDto convertToDto(ChallengeEntity entity, Object... args) {
2929
if (entity != null) {
3030
BeanUtils.copyProperties(entity, dto, "stars", "inputDataTypes", "platform", "operation");
3131
dto.setStatus(ChallengeStatusDto.fromValue(entity.getStatus()));
32-
dto.setPlatform(platformMapper.convertToDto(entity.getPlatform()));
32+
var platformDto = platformMapper.convertToDto(entity.getPlatform());
33+
if (platformDto != null) {
34+
dto.setPlatform(platformDto);
35+
}
3336
if (entity.getOperation() != null) {
3437
dto.setOperation(edamConceptMapper.convertToDto(entity.getOperation()));
3538
}

apps/openchallenges/challenge-service/src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/mapper/ChallengeMapper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ public ChallengeDto convertToDto(ChallengeEntity entity, Object... args) {
3333
BeanUtils.copyProperties(entity, dto, "stars", "inputDataTypes", "platform", "operation");
3434
log.trace("challenge dto before set: {}", dto);
3535
dto.setStatus(ChallengeStatusDto.fromValue(entity.getStatus()));
36-
dto.setPlatform(platformMapper.convertToDto(entity.getPlatform()));
36+
// Only set the platform when it exists. Avoid serializing an empty object with null fields.
37+
var platformDto = platformMapper.convertToDto(entity.getPlatform());
38+
if (platformDto != null) {
39+
dto.setPlatform(platformDto);
40+
}
3741
if (entity.getOperation() != null) {
3842
dto.setOperation(edamConceptMapper.convertToDto(entity.getOperation()));
3943
}

apps/openchallenges/challenge-service/src/main/java/org/sagebionetworks/openchallenges/challenge/service/model/mapper/SimpleChallengePlatformMapper.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ public SimpleChallengePlatformDto convertToDto(
2525
SimpleChallengePlatformEntity entity,
2626
Object... args
2727
) {
28-
SimpleChallengePlatformDto dto = new SimpleChallengePlatformDto();
29-
if (entity != null) {
30-
BeanUtils.copyProperties(entity, dto);
28+
if (entity == null) {
29+
// Preserve null instead of returning an empty object with all fields null.
30+
return null;
3131
}
32+
SimpleChallengePlatformDto dto = new SimpleChallengePlatformDto();
33+
BeanUtils.copyProperties(entity, dto);
3234
return dto;
3335
}
3436
}

0 commit comments

Comments
 (0)