diff --git a/leshan-client-core/src/main/java/org/eclipse/leshan/client/util/LinkFormatHelper.java b/leshan-client-core/src/main/java/org/eclipse/leshan/client/util/LinkFormatHelper.java
index f07d38454c..afcf7dbe6c 100644
--- a/leshan-client-core/src/main/java/org/eclipse/leshan/client/util/LinkFormatHelper.java
+++ b/leshan-client-core/src/main/java/org/eclipse/leshan/client/util/LinkFormatHelper.java
@@ -48,7 +48,6 @@
import org.eclipse.leshan.core.request.ContentFormat;
import org.eclipse.leshan.core.request.ReadRequest;
import org.eclipse.leshan.core.response.ReadResponse;
-import org.eclipse.leshan.core.util.StringUtils;
/**
* An Utility class which help to generate @{link Link} from {@link LwM2mObjectEnabler} and {@link LwM2mModel}.
@@ -269,8 +268,14 @@ protected List> getObjectAttributes(ObjectModel objectModel) {
}
protected Version getVersion(ObjectModel objectModel) {
- if (StringUtils.isEmpty(objectModel.version) || ObjectModel.DEFAULT_VERSION.equals(objectModel.version)) {
- return null;
+ if (versionRegistry.isCoreObject(objectModel.id, version)) {
+ if (versionRegistry.isDefaultVersion(new Version(objectModel.version), objectModel.id, version)) {
+ return null;
+ }
+ } else {
+ if (Version.V1_0.equals(new Version(objectModel.version))) {
+ return null;
+ }
}
return new Version(objectModel.version);
}
diff --git a/leshan-core/src/main/java/org/eclipse/leshan/core/model/LwM2mCoreObjectVersionRegistry.java b/leshan-core/src/main/java/org/eclipse/leshan/core/model/LwM2mCoreObjectVersionRegistry.java
index 13f0954bc6..8d3f13b630 100644
--- a/leshan-core/src/main/java/org/eclipse/leshan/core/model/LwM2mCoreObjectVersionRegistry.java
+++ b/leshan-core/src/main/java/org/eclipse/leshan/core/model/LwM2mCoreObjectVersionRegistry.java
@@ -84,6 +84,11 @@ public Version getDefaultVersion(int objectId, LwM2mVersion lwM2mVersion) {
return null;
}
+ public boolean isCoreObject(int objectId, LwM2mVersion lwM2mVersion) {
+ Map objectIdToVersion = lwm2mVerionToObjectRegistry.get(lwM2mVersion);
+ return objectIdToVersion.get(objectId) != null;
+ }
+
public boolean isDefaultVersion(Version objectVersion, int objectId, LwM2mVersion lwM2mVersion) {
Map objectIdToVersion = lwm2mVerionToObjectRegistry.get(lwM2mVersion);
if (objectIdToVersion != null) {
diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/BootstrapTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/BootstrapTest.java
index f9ab27ae78..8a685ed171 100644
--- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/BootstrapTest.java
+++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/BootstrapTest.java
@@ -355,10 +355,10 @@ public void bootstrapWithDiscoverOnRoot(Protocol givenProtocol, String givenClie
LwM2mResponse firstResponse = bootstrapServer.getFirstResponseFor(bootstrapSession, firstRequest);
assertThat(firstResponse).isInstanceOfSatisfying(BootstrapDiscoverResponse.class, r -> {
assertThat(r).hasCode(ResponseCode.CONTENT);
- assertThat(r.getObjectLinks()).isLikeLwM2mLinks(String.format(
- ">;lwm2m=1.0,0>;ver=1.1,0/0>;uri=\"coap://%s:%d\",1>;ver=1.1,2>,3442/0>,3>;ver=1.1,3/0>",
- bootstrapServer.getEndpoint(givenProtocol).getURI().getHost(),
- bootstrapServer.getEndpoint(givenProtocol).getURI().getPort()));
+ assertThat(r.getObjectLinks()).isLikeLwM2mLinks(
+ String.format(">;lwm2m=1.0,0/0>;uri=\"coap://%s:%d\",1>,2>,3442/0>,3/0>",
+ bootstrapServer.getEndpoint(givenProtocol).getURI().getHost(),
+ bootstrapServer.getEndpoint(givenProtocol).getURI().getPort()));
});
}
@@ -398,10 +398,10 @@ public void bootstrapWithDiscoverOnRootThenRebootstrap(Protocol givenProtocol, S
LwM2mResponse firstResponse = bootstrapServer.getFirstResponseFor(bootstrapSession, firstRequest);
assertThat(firstResponse).isInstanceOfSatisfying(BootstrapDiscoverResponse.class, r -> {
assertThat(r).hasCode(ResponseCode.CONTENT);
- assertThat(r.getObjectLinks()).isLikeLwM2mLinks(String.format(
- ">;lwm2m=1.0,0>;ver=1.1,0/0>;uri=\"coap://%s:%d\",1>;ver=1.1,2>,3442/0>,3>;ver=1.1,3/0>",
- bootstrapServer.getEndpoint(givenProtocol).getURI().getHost(),
- bootstrapServer.getEndpoint(givenProtocol).getURI().getPort()));
+ assertThat(r.getObjectLinks()).isLikeLwM2mLinks(
+ String.format(">;lwm2m=1.0,0/0>;uri=\"coap://%s:%d\",1>,2>,3442/0>,3/0>",
+ bootstrapServer.getEndpoint(givenProtocol).getURI().getHost(),
+ bootstrapServer.getEndpoint(givenProtocol).getURI().getPort()));
});
// re-bootstrap
@@ -423,7 +423,7 @@ public void bootstrapWithDiscoverOnRootThenRebootstrap(Protocol givenProtocol, S
assertThat(secondResponse).isInstanceOfSatisfying(BootstrapDiscoverResponse.class, r -> {
assertThat(r).hasCode(ResponseCode.CONTENT);
assertThat(r.getObjectLinks()).isLikeLwM2mLinks(String.format(
- ">;lwm2m=1.0,0>;ver=1.1,0/0>;uri=\"coap://%s:%d\",0/1>;ssid=2222;uri=\"coap://%s:%d\",1>;ver=1.1,1/0>;ssid=2222,2>,3442/0>,3>;ver=1.1,3/0>",
+ ">;lwm2m=1.0,0/0>;uri=\"coap://%s:%d\",0/1>;ssid=2222;uri=\"coap://%s:%d\",1/0>;ssid=2222,2>,3442/0>,3/0>",
bootstrapServer.getEndpoint(givenProtocol).getURI().getHost(),
bootstrapServer.getEndpoint(givenProtocol).getURI().getPort(),
server.getEndpoint(givenProtocol).getURI().getHost(),
@@ -467,7 +467,7 @@ public void bootstrapWithDiscoverOnDevice(Protocol givenProtocol, String givenCl
LwM2mResponse firstResponse = bootstrapServer.getFirstResponseFor(bootstrapSession, firstRequest);
assertThat(firstResponse).isInstanceOfSatisfying(BootstrapDiscoverResponse.class, r -> {
assertThat(r).hasCode(ResponseCode.CONTENT);
- assertThat(r.getObjectLinks()).isLikeLwM2mLinks(">;lwm2m=1.0,3>;ver=1.1,3/0>");
+ assertThat(r.getObjectLinks()).isLikeLwM2mLinks(">;lwm2m=1.0,3/0>");
});
}
diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/DiscoverTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/DiscoverTest.java
index bff6a6c7b7..8f8935c226 100644
--- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/DiscoverTest.java
+++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/DiscoverTest.java
@@ -101,8 +101,7 @@ public void can_discover_object(Protocol givenProtocol, String givenClientEndpoi
assertThat(response) //
.hasCode(CONTENT) //
.hasValidUnderlyingResponseFor(givenServerEndpointProvider) // */
- .hasObjectLinksLike(
- "3>;ver=1.1,3/0>,3/0/0>,3/0/1>,3/0/2>,3/0/11>,3/0/14>,3/0/15>,3/0/16>");
+ .hasObjectLinksLike("3>,3/0>,3/0/0>,3/0/1>,3/0/2>,3/0/11>,3/0/14>,3/0/15>,3/0/16>");
}
diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/QueueModeTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/QueueModeTest.java
index 1eaba8e1a9..64e273921c 100644
--- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/QueueModeTest.java
+++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/QueueModeTest.java
@@ -105,7 +105,7 @@ public void awake_sleeping_awake_sleeping(Protocol givenProtocol, String givenCl
assertThat(client).isRegisteredAt(server);
Registration registration = server.getRegistrationFor(client);
assertThat(registration.getObjectLinks()).isLikeLinks(
- ">;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",1>;ver=1.1,1/0>,2>,3>;ver=1.1,3/0>,3442/0>");
+ ">;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",1/0>,2>,3/0>,3442/0>");
// Wait for client awake time expiration (20% margin)
assertThat(client).after((long) (AWAKETIME * 0.8), TimeUnit.MILLISECONDS).isAwakeOn(server);
diff --git a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/RegistrationTest.java b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/RegistrationTest.java
index c1d563fa59..cea978a8fb 100644
--- a/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/RegistrationTest.java
+++ b/leshan-integration-tests/src/test/java/org/eclipse/leshan/integration/tests/RegistrationTest.java
@@ -148,7 +148,7 @@ public void register_update_deregister(Protocol protocol, String clientEndpointP
assertThat(client).isRegisteredAt(server);
Registration registration = server.getRegistrationFor(client);
assertThat(registration.getObjectLinks()).isLikeLinks(
- ">;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",1>;ver=1.1,1/0>,2>,3>;ver=1.1,3/0>,3442/0>");
+ ">;rt=\"oma.lwm2m\";ct=\"60 110 112 1542 1543 11542 11543\",1/0>,2>,3/0>,3442/0>");
// Check for update
client.waitForUpdateTo(server, SHORT_LIFETIME, TimeUnit.SECONDS);