---
title: "Slice Metadata Directives"
url: https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives
language: java
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Slice Metadata Directives

Programming language: Java. Other languages: [C++](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/csharp.md), [JavaScript](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/php.md), [Python](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/python.md), [Ruby](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/ruby.md), [Swift](https://docs.zeroc.com/ice/3.8/slice/slice-metadata-directives/swift.md).

## Overview

A metadata directive gives the Slice compilers an instruction about a Slice definition or a Slice file. Most directives customize the code generated for one language mapping, and start with the prefix of this mapping, such as `java:`:

```slice
["java:type:java.util.LinkedList<Integer>"] sequence<int> IntSeq;
```

The general directives have no prefix. For example, `format` selects how Ice marshals class instances, and `deprecated` marks a definition as deprecated.

You place directives in square brackets before the definition they apply to, separated by commas or in consecutive lists, as in `["amd"]["deprecated"]`:

```slice
["amd", "deprecated"]
interface Greeter
{
    string greet(string name);
}
```

A file directive applies to a whole Slice file. You place it in double square brackets before any definition in this file; it can follow `#include` directives:

```slice
[["cpp:dll-export:WIDGET_API"]]
```

Each directive applies only to certain kinds of definitions, listed in its description below.

## General Metadata Directives

### amd

`["amd"]`. Applies to interfaces and operations.

In C++, C#, and Java, the skeleton provides an asynchronous method for the operation, or for each operation of the interface, instead of a synchronous method. Instead of using this directive, you can also derive your servant class from the asynchronous skeleton; see [Operations](https://docs.zeroc.com/ice/3.8/slice/operations/java.md). The other Slice compilers ignore this directive.

### deprecated

`["deprecated"]` or `["deprecated:message"]`. Applies to interfaces, operations, classes, exceptions, structs, sequences, dictionaries, enumerations, enumerators, constants, and fields.

This directive marks a definition as deprecated; see [Deprecating Slice Definitions](https://docs.zeroc.com/ice/3.8/slice/deprecating-slice-definitions.md).

### format

`["format:compact"]` or `["format:sliced"]`. Applies to interfaces and operations.

This directive selects the [encoding format](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slicing-values-and-exceptions/java.md) of the class instances marshaled as the arguments or result of an operation: `format:compact` selects the compact format, and `format:sliced` selects the sliced format. On an interface, it applies to all the operations of the interface; on an operation, it overrides the `format` directive of the enclosing interface.

When neither an operation nor its enclosing interface selects a format, the [Ice.Default.SlicedFormat](https://docs.zeroc.com/ice/3.8/property-reference/ice-default-properties/java.md#ice.default.slicedformat) property selects it.

> **Note**
>
> This directive does not apply to user exceptions: Ice always marshals them in the sliced format.

### marshaled-result

`["marshaled-result"]`. Applies to interfaces and operations.

This directive lets a servant marshal the results of an operation as soon as it computes them, typically while it holds the lock that protects the data it returns. The mapped skeleton method returns a “marshaled result” struct or class whose constructor marshals the return value and out parameters immediately.

On an interface, this directive applies to every operation that the interface defines. The Slice compiler changes the mapping of an operation only when its return type or one of its out parameters is a class, struct, sequence, or dictionary. This directive affects the server-side mapping in C++, C#, and Java, and has no effect on the client-side mapping.

For example:

```slice
module M
{
    sequence<int> IntSeq;
    sequence<IntSeq> IntIntSeq;
    sequence<string> StringSeq;

    class Grid
    {
        StringSeq xLabels;
        StringSeq yLabels;
        IntIntSeq values;
    }

    interface GridIntf
    {
        // We want to marshal the returned Grid object within a lock,
        // and return a consistent object not affected by concurrent calls to
        // clearValues.
        ["marshaled-result"]
        ["cs:identifier:GetGrid"]
        Grid getGrid();

        void clearValues();
    }
}
```

The mapped skeleton method for `getGrid` is:

```java
GridIntf.GetGridMarshaledResult getGrid(com.zeroc.Ice.Current current);
```

where `GetGridMarshaledResult` is a nested static class with a constructor that accepts a parameter for the return value, followed by `Current`:

```java
// Generated server-side code
public interface GridIntf extends com.zeroc.Ice.Object {
    public static class GetGridMarshaledResult implements
          com.zeroc.Ice.MarshaledResult {
        public GetGridMarshaledResult(
            Grid returnValue,
            com.zeroc.Ice.Current current) {
            ...
        }
    }
    ...
}
```

A typical implementation of the `getGrid` operation in your servant would be:

```java
@Override
public GridIntf.GetGridMarshaledResult getGrid(com.zeroc.Ice.Current current) {
    synchronized (_mutex) {
       // marshal _grid field within synchronization
       return new GridIntf.GetGridMarshaledResult(_grid, current);
    }
}
```

> **Warning**
>
> A marshaled-result instance is specific to a request. Do not cache a marshaled result and return it for another request.

### oneway

`["oneway"]`. Applies to operations.

This directive restricts an operation to oneway invocations. The operation cannot have a return type, out parameters, or an exception specification.

### suppress-warning

`[["suppress-warning"]]` or `[["suppress-warning:category, ..."]]`. Applies to a Slice file.

This directive suppresses Slice compiler warnings for all the definitions in the Slice file. Without a category, it suppresses all warnings; with one or more categories, it suppresses only the warnings in these categories:

| **Category** | **Description** |
| --- | --- |
| `all` | Suppress all Slice compiler warnings. Equivalent to `[["suppress-warning"]]`. |
| `deprecated` | Suppress warnings related to deprecated features. |
| `invalid-comment` | Suppress warnings related to invalid doc comments. |

## Language-Specific Metadata Directives

Java metadata directives use the `java` prefix.

### java:buffer

`["java:buffer"]`. Applies to sequences of `byte`, `short`, `int`, `long`, `float`, and `double`.

This directive maps the [sequence](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences/java.md) to a subclass of `java.nio.Buffer`.

### java:getset

`["java:getset"]`. Applies to fields, structs, classes, and exceptions.

This directive adds accessor and modifier methods ([JavaBean methods](https://docs.zeroc.com/ice/3.8/slice/fields/java.md)) for fields.

### java:identifier

`["java:identifier:name"]`. Applies to any definition, parameter, or field.

The generated Java code uses `name` instead of the Slice identifier. For example:

```slice
struct Descriptor
{
    ["java:identifier:ephemeral"]
    bool transient;
}
```

The field `transient` maps to `ephemeral` in Java. The default mapping, `transient`, is a Java keyword.

> **Warning**
>
> When you apply this directive to a module that contains classes or exceptions, or directly to a class or an exception, you need to install a [Slice loader](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slice-loaders/java.md) in communicators that receive (unmarshal) these classes or exceptions.

### java:package

`["java:package:enclosing-package"]` or `[["java:package:enclosing-package"]]`. Applies to top-level modules and Slice files.

This deprecated directive nests the Java package of the module, or of every top-level module in the file, in `enclosing-package`: with `["java:package:com.acme"]` on `module Demo`, the generated code is in the package `com.acme.Demo`. Use `java:identifier` on your modules instead.

> **Warning**
>
> When you apply this directive to a module that contains classes or exceptions, communicators that receive (unmarshal) these classes or exceptions need a [Slice loader](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/slice-loaders/java.md) to locate their Java classes. Setting the matching [Ice.Package.*module*](https://docs.zeroc.com/ice/3.8/property-reference/ice-properties/java.md#ice.package.module) property or [Ice.Default.Package](https://docs.zeroc.com/ice/3.8/property-reference/ice-default-properties/java.md#ice.default.package) to `enclosing-package` also works.

### java:serializable

`["java:serializable:class"]`. Applies to `sequence<byte>`.

This directive maps the sequence to `class`, the fully qualified name of a Java class that implements `java.io.Serializable`, so that you can transmit serializable Java objects without defining them in Slice. Ice transmits the Java serialization of the object as a sequence of bytes, which other language mappings receive as a plain byte sequence. See [Filling a Sequence of Bytes with a Serializable Object](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences/java.md#filling-a-sequence-of-bytes-with-a-serializable-object) for an example.

### java:serialVersionUID

`["java:serialVersionUID:uid"]`. Applies to classes, exceptions, and structs.

The Slice-to-Java compiler computes a default value for the `serialVersionUID` field of the Java classes mapped from Slice [classes](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/classes/java.md), [exceptions](https://docs.zeroc.com/ice/3.8/slice/exceptions/java.md), and [structs](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/structures/java.md). This directive replaces this value with `uid`, an integer literal. The application is then responsible for updating the UID whenever changes to the Slice definition affect the serializable state of the type.

### java:type

`["java:type:instance-type"]` or `["java:type:instance-type:formal-type"]`. Applies to sequences and dictionaries.

This directive maps a [sequence](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/sequences/java.md) or [dictionary](https://docs.zeroc.com/ice/3.8/slice/user-defined-types/dictionaries/java.md) to a custom Java type.

### java:UserException

`["java:UserException"]`. Applies to operations.

The methods of the mapped servant interface and class declare `throws com.zeroc.Ice.UserException`, so they can throw any user exception, regardless of the exception specification of the Slice operation. This directive does not change the methods of the generated proxies.
